混淆视听的感脚(二)

 1.对下面代码,打印出来的count是多少

    @Test
    public void testsA2() {
        //        int i = Integer.MAX_VALUE;
        //        int j = i+1;
        //        System.out.println(j);
        //        System.out.println(Integer.MIN_VALUE);
        int count = 0;
        int begin = Integer.MAX_VALUE - 100;
        int end = Integer.MAX_VALUE;
        for (int i = begin; i <= end; i++) {
            count++;
        }
        System.out.println(count);
    }

其实结果不是101,更不是100.why?打开注释行代码,会发Integer.MAX_VALUE+1 = Integer.MIN_VALUE,导致该程序在for循环的时候跳不出来,所以卡死了,需要手动结束。

2. 

  /**
     * int tmp = j;
     * j = j + 1;
     * j = tmp?;
     */
    @Test
    public void testsA() {
        int j = 0;
        for (int i = 0; i < 100; i++)
            j = j++;
        System.out.println(j);
    }

  输出的j为0

3.换个角度看

  

@Test
    public void testsA22() {
        double count = 1.0 / 0.0;
        System.out.println(count);

        //while (i != i + 0) {} String i = "what a fucky day";
        //while (i <= j && j <= i && i != j) {} Integer i = new Integer(0);
        //(i != 0 && i == -i)  int i = Integer. MIN_VALUE; long i = Long. MIN_VALUE;
    }
原文地址:https://www.cnblogs.com/havenenjoy/p/4552803.html