// Helene Martin, CSE 142 // Prompts the user for words until the sentinel is reached. // goal: demonstrates usuage of the while loop. This particular // usage is called a sentinel loop. // also includes a cumulative sum and a good use of a class constant. import java.util.*; public class WordSum1 { public static final String SENTINEL = "quit"; public static void main(String[] args) { Scanner console = new Scanner(System.in); int letters = 0; System.out.print("Type a word or \"" + SENTINEL + "\" to quit: "); String word = console.next(); while (!word.equals(SENTINEL)) { letters = letters + word.length(); System.out.print("Type a word or \"" + SENTINEL + "\" to quit: "); word = console.next(); } System.out.println("You typed " + letters + " letters"); } }