下面的这个小程序,我在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+"个字符");
}
}
/*******程序如下
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+"个字符");
}
}
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+ "个字符 ");
}
}
用这个两个环境应该一样了。至于为什么你可自己想想。 (: