请问:
这个程序:
class lesson22
{
 public static void main(String[]args)
 {
  int x = System.in.read();
  while(x!='q')
  {
   System.out.println((char)x);
   x = System.in.read();
  }
 }
}
1.为什么不能编译呢 出现2个错误 都指向read()的左括号
2,那3个x是相同的吗 

解决方案 »

  1.   

    你要加上  1,import java.io.*; 2,try 和 catch
    import java.io.*;class   lesson22
    {
     public   static   void   main(String[]args)
     {
      int x = 0;
      try {
        x = System.in.read();
      }
      catch (IOException ex) {
      }
       while(x!='q')
       {
         System.out.println((char)x);
        try {
          x = System.in.read();
        }
        catch (IOException ex1) {
        }
       }
     }
    }
      

  2.   

    import java.io.IOException;class   lesson22
    {
      public   static   void   main(String[]args)
      {
        int x = 0;
    try {
    x = System.in.read();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
        while(x!='q')
        {
          System.out.println((char)x);
          try {
    x   =   System.in.read();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
        }
      }
      

  3.   

       
      while(x!='q')   // != 有问题吧
       用equals()吧
      

  4.   

    To:7楼的  楼主定义的是int ,如是String 应该象你说的equals