while(true){
            try { 
                int ch = System.in.read();
               
             
                System.out.println((char)ch+"while中--------------------------------------");
            } catch (IOException e) { 
                
                e.printStackTrace();
            }
        } 
为什么我输入一个c,他给我打印  cwhile-----------------
接着居然打印出2次while--------------------------

解决方案 »

  1.   

    int ch输入的为什么是c?不明白你说的意思是什么。
      

  2.   

    所以你打了个C 敲了下回车  就回循环3次了 你如果不转换成CHAR 你可以看到10 13的
    下回车键代表了两个字符\r\n,\r 的 ASCII 码值是 10,\n 是 13
      

  3.   

    回车键代表了两个字符\r\n,\r 的 ASCII 码值是 10,\n 是 13
    你打了个C 敲了下回车 就回循环3次了 你如果不转换成CHAR 你可以看到10 13 两个ASCII 码值