import java.util.*; // NOTE: this program doesn't quite work if // the user's first and only response is "quit" // This was meant to be an example of a sentinel // loop, while loop, and cumulative algorithm public class LongestWordCount { public static void main(String[] args) { Scanner console = new Scanner(System.in); String stringSum = ""; System.out.print("next token or \"quit\"? "); String word = console.next(); int longestWordCount = word.length(); while (!word.equals("quit")) { if (word.length() > longestWordCount) { longestWordCount = word.length(); } stringSum = stringSum + word; System.out.print("next token or \"quit\"? "); word = console.next(); } System.out.println("concatenated strings: " + stringSum); System.out.println("The longest word has " + longestWordCount + " characters."); } }