Loading...
Loading...
Loading...
For a spelling contest, the teacher picks the longest word from a sentence. Read the sentence and print the longest word and its length. If two or more words have the same longest length, print the one that comes first.
Example 1
Input
I love programming in Java
Output
programming 11
Example 2
Input
red blue pink
Output
blue 4
blue and pink are both 4 letters; blue comes first.
Try the problem first. Open one hint at a time.
Split the trimmed line with split("\\s+") to get the words.
Keep the best word so far and replace it only when a word is strictly longer.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor