// Helene Martin, CSE 142 // Prompts the user for several words and reports the total number of letters typed. // Demonstrates the use of a sentinel. import java.util.*; public class WordSum { public static final String SENTINEL = "quit"; public static void main(String[] args) { Scanner console = new Scanner(System.in); int letters = 0; // pull out the first prompt ('post') // so word is initialized to something the user // typed in and should be added to the letter count System.out.print("Type a word (or \"" + SENTINEL + "\" to exit): "); String word = console.next(); while (!word.equals(SENTINEL)) { // order of statements needs to be swapped when first 'post' is taken out letters += word.length(); System.out.print("Type a word (or \"" + SENTINEL + "\" to exit): "); word = console.next(); } System.out.println("Total letters typed: " + letters); } }