1+2+...+n>=max问题的求解

package Hello;

public class Demo1 {
    public static void main(String args[]) {
        long sum = 0, i = 1, N = 0, max = 1931918;
        while(true) {
            sum = sum + i;
            if(sum > max) {
                N = i-1;
                break;
            }
            i ++;
        }
        System.out.println("满足1+2+...+n <= "+max+"的最大整数是:"+ N);
    }
}

 

posted on 2018-02-28 14:59  letwant  阅读(128)  评论(0编辑  收藏  举报

导航