Question: how do I do this one I can not figure it out 1 . The following program contains 6 errors. ` ` ` public class

how do I do this one I can not figure it out
1. The following program contains 6 errors.
```
public class Mystery
{
public static void main(String[] args)
{
Scanner in = new Scanner("example.txt");
countWords(in);
}
// counts total lines and words in the input scanner.
public static void countWords(Scanner input)
{
Scanner input = new Scanner("example.txt");
int lineCount =0;
int wordCount =0;
while (input.nextLine())
{
String line = input.line(); // read one line
lineCount++;
while (line.next())// tokens in line
{
String word = line.hasNext;
wordCount++;
}
}
System.out.println("Lines: "+ lineCount);
System.out.println("Words: "+ wordCount);
}
}
```
Correct the errors and submit a working version of the program. The corrected version of the program should produce the following output:
Lines: 5
Words: 21
when it is run on the following input file, example.txt:
hello how are you
1234
I am fine
This line has a large number of words on it
how do I do this one I can not figure it out 1 .

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 Programming Questions!