Question: Write a program named CountWords.java that: has a method called wordCount that accepts a String as its parameter and returns the number of words in

Write a program named CountWords.java that:

has a method called wordCount that accepts a String as its parameter and returns the number of words in the String. A word is a sequence of one or more nonspace characters.

For example:

wordCount("Elephant") would return 1 wordCount(how are you) would return 3 wordCount( this string has spaces ) would return 4

has a main() method that: Prompts the user for a phrase Then prints the number of words in the phrase as follows:

System.out.printf("Your phrase has %d words.", wordCount(phrase)); Sample Output:

Enter a phrase: Go Bison 2017!!! Your phrase has 3 words.

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!