Question: for Question 7 import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CountWords { public static void main(String[]args) throws FileNotFoundException{ Scanner console = new Scanner(System.in); Scanner

for Question 7

import java.io.File;

import java.io.FileNotFoundException;

import java.util.Scanner;

public class CountWords {

public static void main(String[]args)

throws FileNotFoundException{

Scanner console = new Scanner(System.in);

Scanner input = getInput(console);

int count = 0;

while (input.hasNext()) {

String word = input.next();

count++;

}

System.out.println("total words =" + count);

}

public static Scanner getInput (Scanner console)

throws FileNotFoundException{

System.out.print("input file name?");

File f = new File (console.nextLine());

while(!f.canRead()) {

System.out.println("File not found. Try agaon.");

System.out.print("input file name?");

f = new File (console.nextLine());

}

return new Scanner(f);

}

}

for Question 7 import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class CountWords

Question 7 1.5 pts Which of the following statements CORRECTLY describe the program CountWords listed on pp 421-422? Check all that apply. The program constructs two Scanner objects: one for interactive input and another one for file processing. O The program uses a File method called canRead to determine if the file exists and can be read. The program processes a file line-by-line. The header for the method getlnput reads: public static Scanner getlnput (Scanner console) throws FileNotFoundException The method getlnput returns a Scanner object associated with a specific file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!