// Another way to solve the sentinel loop problem. import java.util.*; public class SentinelSum2 { public static void main(String[] args) { Scanner console = new Scanner(System.in); int sum = 0; int number = 1; // dummy value (anything but -1, so loop will start) while (number != -1) { System.out.print("Enter a number (-1 to quit): "); number = console.nextInt(); // don't add the number to the total if it is the sentinel if (number != -1) { sum += number; } } System.out.println("The total was " + sum); } }