日期:2014-05-20  浏览次数:20684 次

一个不足10行的程序怎么就不是很正常呢?大家帮忙看看吧
public   class   SystemTest
{
public   static   void   main(String   args[])   throws   Exception
{
int   count   =   0;
System.out.println( "Enter   characters,   'q '   to   quit. ");
while   ( 'q '!=   (char)   (count   =   System.in.read()))
{
System.out.print((char)   count);
}

}
}
该程序将键盘输入的字符输出到屏幕,遇到字母q时程序终止
但是在eclipse中运行后可以在控制台中显示输出   但按到q时怎么不停止呢??


------解决方案--------------------
it 's base console
------解决方案--------------------
没有错误啊,我试了,运行的很好啊
------解决方案--------------------
mission completed, test passed...
------解决方案--------------------
那是 eclipse的问题

------解决方案--------------------
在eclipse里面运行的时候eclipse只是把输出流System.out拦截下来在ide中显示,而并没有实现System.in的重定向。这个程序只能在cmd中运行,也就是前面弟兄讲的console
------解决方案--------------------
好啊我也是新手想问一下 如果在eclipse怎么改写这个程序呢?谢谢!
------解决方案--------------------
没有错,可以,
------解决方案--------------------
JCreator运行没问题
------解决方案--------------------
eclipse里也没问题
------解决方案--------------------
public class QTest{
public static void main(String[] args)throws Exception{
int count=0;
System.out.println( "Please input characters,if character is 'q ',quit! ");
count=System.in.read();
while ( 'q '!=(char)count){
System.out.println((char)count);
}

}
}
我的为什么也停不下来呀,郁闷!