下面的这个小程序,我在JCreator和JBuilder里面运行,得到了不同的结果?!在JBuilder里是准确的,在JCreator用控制台运行时,总是提示多计算一个字符,这是为什么呢?
/*******程序如下
import java.io.*;
public class TestSimpleIO {    public static void main(String[] args) throws IOException{
        int b,count=0;
        while((b=System.in.read())!='\n'){
                count++;
                System.out.print((char)b);
                }
        System.out.println("共计输入了"+count+"个字符");
    }
}

解决方案 »

  1.   

    package my.test;import java.io.IOException;
    public class Main {
    public static void main(String[] args) throws IOException {

    int   b,count=0; 
            while(true){
            
             b=System.in.read();
            
             if(b==10 || b==13)break;
            
             count++; 
             System.out.print((char)b); 
            }
            
            
            System.out.println( "共计输入了 "+count+ "个字符 "); 
    }
    }
    用这个两个环境应该一样了。至于为什么你可自己想想。  (:
      

  2.   

    我知道在控制台上按回车键相当于输入\r 和\n的组合,但是在JBuilder中为啥就与JCreator中识别的不一样呢?!
      

  3.   

    这个应该是具体的IDE实现上的问题了.JBuilder 是自己的 控制台.JCreator 记得好像使用的是Dos的控制台.