`

实例041 - 循环的极限

 
阅读更多

心法领悟041:了解变量的取值范围

public class CycUtmost {
    public static void main(String[] args) {
        int end=Integer.MAX_VALUE;// 定义循环终止数
        int start=end-5;// 定义循环起始数
        int count=0;// 定义循环计数器
        System.out.println("end=" + end);
        System.out.println("stt=" + start);
        for (int i = start; i <= end; i++) {// 执行循环
            count++;// 循环计数
            if(count > 8){
            	break;
            }
            System.out.println("i=" + i);
        }
        // 输出循环计数器

        System.out.println("本次循环次数为:"+count);
    }
}

 

end=2147483647
stt=2147483642
i=2147483642
i=2147483643
i=2147483644
i=2147483645
i=2147483646
i=2147483647
i=-2147483648
i=-2147483647
本次循环次数为:9

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics