我的语句如下:不知道错在那里?                      try
                      {
                      x=System.in.read();
                      }catch(Exception e){}
                      while(x!='q')
                      {
                               System.out.println((char)x);
                               x=System.in.read();
                               try
                {
        x=System.in.read();
        }catch(Exception e){}
                       }

解决方案 »

  1.   

    楼主这样的编程习惯不好,起码向我这样
                          try 
                          { 
                          x=System.in.read(); 
                          }catch(Exception e){e.printStackTrace();} 
                          while(x!='q') 
                          { 
                                  System.out.println((char)x); 
                                  x=System.in.read(); 
                                  try 
                    { 
            x=System.in.read(); 
            }catch(Exception e){e.printStackTrace();} 
                          }
      

  2.   

    楼主的意思是这样吧:
                   try {
    int x = System.in.read();
    while ((char) x != 'q') {
    System.out.println((char) x);
    x = System.in.read();
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
      

  3.   

     try { 
         x=System.in.read(); 
     }catch(Exception e){} 
      while(x!='q') { 
         System.out.println((char)x); 
         x=System.in.read(); //没有TRY
        try { 
           x=System.in.read(); 
         }catch(Exception e){} 
      }
      

  4.   


    try{
    do{
    x=System.in.read(); 
    System.out.println((char)x); 
    }while(x!='q')}catch{Exception e){
    e.printStackTrace();
    }这样比较合适
      

  5.   

    int x = 0;  //少了一句
    try { 
        x = System.in.read(); 
    } catch (Exception e) {
        //Nothing to do

    while (x != 'q') { 
        System.out.println((char) x); 
        //x = System.in.read();  //这句多余
        try { 
            x = System.in.read(); 
        } catch (Exception e) {
            //Nothing to do
        } 
    }
      

  6.   

    try{}cath{}不是给你摆样子的
    请在catch中的添加异常的处理
    要么就不用try/catch
      

  7.   

    public class Demo{
    public static void main (String[] args) {
    int x = 0;
    do{
        try { 
            x = System.in.read();
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println((char)x);
    }while (x != 'q');
    }
    }楼主这样写的话,代码可能会少一点噢。