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