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时怎么不停止呢??

解决方案 »

  1.   

    楼上用的是eclipse还是直接 javac java?
    是键盘输入 控制台显示出来的么?
    按 q 就停止了?
      

  2.   

    mission completed, test passed...
      

  3.   

    在eclipse里面运行的时候eclipse只是把输出流System.out拦截下来在ide中显示,而并没有实现System.in的重定向。这个程序只能在cmd中运行,也就是前面弟兄讲的console
      

  4.   

    好啊我也是新手想问一下 如果在eclipse怎么改写这个程序呢?谢谢!
      

  5.   

    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);
        }
        
      }
    }
    我的为什么也停不下来呀,郁闷!
      

  6.   

    import java.io.*;public class Test
    {
    public static void main(String[] args)throws Exception
    {
    char c;
    while(true){
    if((c=(char)System.in.read())!='q')System.out.println(c);
    else break;
    }
    }
    }
      

  7.   

    IDE工具的问题
    如果初学,建议使用JCreator
      

  8.   

    while ('q'!= (char) (count = System.in.read()))你无法输入单个的'q'输入的是'q\n'