import java.io.*; // import java.lang.*; /* Sample application: enter 10 integer values (on the command line) and print their sum Compiler: javac Sample1.java Run: java Sample1 */ public class Sample1 { // This is the starting point for the execution of the program public static void main(String[] args) throws IOException { // we declare some variables that we need later int sum, i, number; // we generate an input stream, reading from the keyboard BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in)); // we generate an output stream, writing to the console PrintWriter screen = new PrintWriter(System.out, true); // initialise the aggregate sum variable sum = 0; // iterate 10 times for (i = 0; i<10; i=i+1) { screen.print("Enter an integer: "); screen.flush(); number = Integer.parseInt(keyboard.readLine().trim()); sum = sum + number; } screen.println("Sum = "+sum); } }