int n = 100;
for(;;){}
Systemm.out.println(n);

解决方案 »

  1.   

    因为for不能正常结束,导致println那句不可达~~为啥不能正常结束?标准上关于for正常终止是这样说的:
    A basic for statement can complete normally iff at least one of the following is true:
    .The for statement is reachable, there is a condition expression(LZ没有条件表达式), and the condition expression is not a constant expression with value true.
    .There is a reachable break statement that exit the for statement.(LZ也没有break跳出for循环)
    综上:Systemm.out.println(n)不可达。
      

  2.   

    这个我当初也想过。可是这个呢。这个是能编译成功的哦;
    int n = 100;
    while(n>0){}
    System.out.println(n);
    不知道是什么原因,望解答。谢谢了。
      

  3.   

    因为在编译的时候没有用100去替换n,如果把n声明为final你再试试~~
      

  4.   

    这是标准上的规定。因为编译器在编译的时候就知道条件表达式永远为真,但是又没有break语句来跳出,所以后面的println是不可达的~~至于为啥在编译的时候就知道条件表达式为真你可以搜一下:constant expression。一会就扯远了~~其实没必要在这些小地方纠结,没啥意义
      

  5.   

    嗯,谢谢了。我还以为我对for了解透顶了。结果,想不到这个我还真不知道。今天长知识了。谢谢楼上的大大