Sum Problem 数列求和,如果用公式中间结果可能超过int_max import java.io.*; import java.util.*; public class Main { public static void main(String args[]) { Scanner cin = new Scanner(System.in); int n,sum,i; while(cin.hasNextInt()) { n = cin.nextInt(); for(i=1, sum=0;i<=n;i++) sum+=i; System.out.println(sum); System.out.println(); } } }