// Whilesum.java (c) 2004 Kari Laitinen // http://www.naturalprogramming.com // 2004-10-10 File created. // 2004-12-19 Last modification. import java.util.* ; class Whilesum { public static void main( String[] not_in_use ) { Scanner keyboard = new Scanner( System.in ) ; int integer_from_keyboard = -1 ; int sum_of_integers = 0 ; System.out.print( "\n This program calculates the sum of the integers" + "\n you type in from the keyboard. By entering a" + "\n zero you can terminate the program. \n\n" ) ; while ( integer_from_keyboard != 0 ) { System.out.printf( " Current sum: %8d Enter an integer: ", + sum_of_integers ) ; integer_from_keyboard = keyboard.nextInt() ; sum_of_integers = sum_of_integers + integer_from_keyboard ; } } }