longestWord
Category: Programming
Author: Marty Stepp and Ruth Anderson
Book Chapter: 4.3
Problem: longestWord
Write a static method named longestWord that accepts a string as its parameter and returns the length of the longest word in the string. A word is a sequence of one or more non-space characters (any character other than the space character, ' ' ). Here are some example calls to your method and their expected results: Call Value | Returned --------------------------------------------------------|---------- longestWord("to be or not to be") | 3 longestWord("oh hello, how are you?") | 6 longestWord("I am OK") | 2 longestWord(" this example has many spaces ") | 7 longestWord("test") | 4 longestWord("") | 0 longestWord(" ") | 0 Note that the string might be empty, might not contain any words, might begin with spaces, and might contain words separated by multiple spaces. You may assume that the string doesn't contain any other whitespace characters such as tabs or newlines. You may not use auxiliary objects such as Scanner or StringTokenizer to solve this problem.