logo CodeStepByStep logo

wordCount

Language/Type: Java string parameters return
Related Links:

Write a method named 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 non-space characters (any character other than ' '). For example, the call of wordCount("hello, how are you?") should return 4.

Constraints: Do not use a Scanner to help you solve this problem. Do not use any data structures such as arrays to help you solve this problem. Do not use the String method split on this problem. But you can declare as many simple variables like int, char, etc. as you like. Declaring String variables is also fine.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.