import java.util.Scanner; // bring in Scanner class so we can use it public class SumNumbers /** This class illustrates running sum * and reading to end of input. **/ { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); //outside of while loop, declare and initialize sum int sum=0, num; System.out.print(0); // use ctrl D to exit while (keyboard.hasNext()) { num = keyboard.nextInt(); System.out.printf(" + %d",num); sum += num; } // after fall out of while loop, sum should contain the Sum of all // integers that were read in. System.out.println(" = " + sum); } }