import java.util.Scanner; /** Add.java - The user is going to type one number per line, and we will * add up all these numbers. The user will signal the end by entering -1. */ public class Add { public static void main(String [] args) { Scanner kbd = new Scanner(System.in); int total = 0; while(kbd.hasNextLine()) { String line = kbd.nextLine(); int value = Integer.parseInt(line); if (value == -1) break; total += value; } System.out.printf("The total is %d.\n", total); } }