The following program contains 6 errors. 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
1 2 3 4
i am fine
this line has a large number of words on it
public class oops6 {
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. {
string line = input.line(); // read one line
linecount++;
while (line. { // tokens in line
string word = line.hasnext;
wordcount++;
}
}
system.out.println("lines: " + linecount);
system.out.println("words: " + wordcount);
}
}

Solved
Show answers

Ask an AI advisor a question