使用System.in从控制台读取int值
import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException;/** 来 自 时代Java**/ public class Standard { public static void main(String args[]) throws IOException { BufferedReader cin = new BufferedReader(new InputStreamReader( System.in)); String number; int total = 0; while ((number = cin.readLine()) != null) { try { total += Integer.parseInt(number); } catch (NumberFormatException e) { System.err.println("Invalid number in input"); System.exit(1); } } System.out.println(total); /** 来 自 时代Java公众号 - nowjava.com **/ } }