/** * Sum of integers. * 计算前N个自然数的和可以根据公式 * */ public class SumOfInteger { public static void main(String[] args) { int n = 100; // TODO: sum = 1 + 2 + ... + n int sum = (1 + n) * n / 2; System.out.println(sum); } }
Sign in to make a reply
杜梅_vii