// Zorah Fung, CSE 142 // An example of using a sentinel loop and a max algorithm import java.util.*; public class WhileLoops { public static void main(String[] args) { Scanner console = new Scanner(System.in); int totalChars = 0; System.out.print("Type a word (or \"quit\" to exit): "); // post String word = console.next(); // post int longestLength = 0; while (!word.equals("quit")) { totalChars += word.length(); if (word.length() > longestLength) { longestLength = word.length(); } System.out.print("Type a word (or \"quit\" to exit): "); // post word = console.next(); // post } System.out.println("The total number of characters is: " + totalChars); System.out.println("The longest word is " + longestLength + " characters."); } }