Question: Complete the program named CountWords below so that it reads in a line, determines the number of words in the line, and prints out that
Complete the program named CountWords below so that it reads in a line, determines the number of words in the line, and prints out that number.
For example, given the sentence "Joe jumps to grab the ball", which has six words, the program would print 6.
Complete the following file:
CountWords.java
import java.util.Scanner;
/** Counts the number of words in a line. Input: a string containing the line Output: the number of words in the line */ public class CountWords { public static void main(String[] args) { // your work here
Scanner in = new Scanner(System.in); while (in.hasNext()) { // more work here
}
// more work here
System.out.println(count); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
