解决方案 »

  1.   

    第一种好一些if(count++>10){  
    count++ 操作存在迷惑性
    不如第一种把count++ 单独提出去看着明白些
      

  2.   

    要是考虑第三种答案的话,可以试试回答两种都不太好,改造一下while的判定条件使其成为有限循环public class TestAB {
        public static void main(String[] args) throws Exception {
            try {
                (new TestAB()).a();
            } catch (Exception e) {
            }
            try {
                (new TestAB()).b();
            } catch (Exception e) {
            }
            try {
                (new TestAB()).c();
            } catch (Exception e) {
            }
        }    private void a() throws Exception {
            int count = 0;
            while (true) {
                count++;
                if (count > 10) {
                    System.out.println(count);
                    抛异常();
                }
            }
        }    private void b() throws Exception {
            int count = 0;
            while (true) {
                if (count++ > 10) {
                    System.out.println(count);
                    抛异常();
                }
            }
        }    private void c() throws Exception {
            int count = 0;
            while (count <= 10) {
                count++;
                if (count > 10) {
                    System.out.println(count);
                    抛异常();
                }
            }
        }    private void 抛异常() throws Exception {
            throw new Exception();
        }
    }
    输出:
    11
    12
    11如果只让选a或者b的话,a相对好一些;b到12时才检出问题,抛异常,有逻辑错误