Discuss / Java / 打卡交作业

打卡交作业

Topic source
public class SumOfInteger {

    public static void main(String[] args) {
        int n = 100;
        int sum = 0;
        for (int i = 0; i < n + 1; i++) {
            sum += i;
        }
        System.out.println(sum);
    }

}

lookphp

#2 Created at ... [Delete] [Delete and Lock User]

按公式处理,兄弟!

// TODO: sum = 1 + 2 + ... + n

int sum = ((1+n)*n)/2;


  • 1

Reply