while((System.in.read())!=-1)
这个可以中断的
int a=System.in.read();
不可以

解决方案 »

  1.   

    i agree something that have been descripted by wawaxp
    读入a和while没有关系,当然会一直循环
      

  2.   

    上面一个程序int a=System.in.read();不在循环中,只执行一次,如果a!=-1,则循环自然会无限执行下去。下面一个程序在每次循环开始时都要先执行System.in.read(),然后判断是否不等于-1,如果某次不满足这个条件,循环自然就会中止。