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 sum = 0; // pull one prompt/read ("post") out of the loop String response = getLine(console); while (!response.equals(SENTINEL)) { sum += response.length(); // moved to top of loop response = getLine(console); } System.out.println("You typed a total of " + sum + " characters."); } public static String getLine(Scanner console) { System.out.print("Type a line (or \"" + SENTINEL + "\" to exit): "); return console.nextLine(); } }