2.Write a method named longestWord that accepts a String as its parameter and re
ID: 3540344 • Letter: 2
Question
2.Write a 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).
You may assume that the string doesn't contain any other white-space characters such as tabs or newlines.
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
please do not use trim
Call
Value returned
longestWord("to be or not to be")
3
longestWord("oh hello, how are you?")
6
longestWord("I am OK")
2
Explanation / Answer
Sample output
Enter a String
to be or not to be
Maximum length of a word in this String is :3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.