/* Marty Stepp, CSE 142, Autumn 2008 This program prompts the user for numbers until -1 is typed, then displays which number was the largest number typed. Example output: Type a number (or -1 to quit): 10 Type a number (or -1 to quit): 30 Type a number (or -1 to quit): 15 Type a number (or -1 to quit): 20 Type a number (or -1 to quit): -1 The biggest number you typed was 30 */ import java.util.*; public class Biggest { public static final int SENTINEL = -1; public static void main(String[] args) { Scanner console = new Scanner(System.in); // moved one "post" out of loop System.out.print("Type a number (or " + SENTINEL + " to quit): "); int number = console.nextInt(); int max = number; // longest number seen so far while (number != SENTINEL) { if (number > max) { max = number; // moved to top of loop } System.out.print("Type a number (or " + SENTINEL + " to quit): "); number = console.nextInt(); } if (max != SENTINEL) { System.out.println("The biggest number you typed was " + max); } } }