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

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!