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
Get step-by-step solutions from verified subject matter experts
