Question: Implement the method wordCount as described in the problem: This includes having identical characters and spacing. Please note: This is NOT an interactive program, therefore,

Implement the method wordCount as described in the problem: This includes having identical characters and spacing.
Please note: This is NOT an interactive program, therefore, do NOT use Scanner.
The method wordCount should accepts a String as its parameter and return the number of words in the String. A word is a sequence of one or more nonspace characters (any character other than whitespace ).
You must use character method. In particular, you are NOT allowed to use String trim() and String split().
Some examples of expected output:
The call wordCount(hello) should return 1
The call wordCount(how are you?) should return 3
The call wordCount( how are you?) should return 3
The call wordCount(how are you? ) should return 3
The call wordCount(how are you ?) should return 4
The call wordCount(I am 3 years old) should return 5
The call wordCount(3 x 4=12) should return 5
The call wordCount(Characters !@#$%^&*) should return 2
The call wordCount() should return 0

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!