The complete program is given below.
import java.io.*; class AddUpAllSentinel { public static void main ( String[] args ) throws IOException { int value; // the value of the current integer int sum = 0; // initialize sum String line; BufferedReader stdin = new BufferedReader( new InputStreamReader( System.in ) ); // get first integer System.out.println("Enter first integer:"); line = stdin.readLine(); value = Integer.parseInt( line.trim() ); int count = 0; // initialize count while ( value >= 0 ) { sum = sum + value; // add to the sum count = count + 1; // increment count System.out.println("Enter a number:"); line = stdin.readLine(); value = Integer.parseInt( line.trim() ); } System.out.println( "Grand Total: " + sum ); } }