import java.io.IOException; public class InputStreamDemo2 { public static void main(String[] args) { //Read digits that spell out an integer value. //For example, the digits "123" spell out the number 123. try { int sum = 0; int i; while ((i = System.in.read()) != -1 && Character.isDigit(i)) { sum *= 10; sum += Character.getNumericValue(i); } System.out.println("sum == " + sum); } catch (IOException e) { System.err.println(e.getMessage()); } } }