BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String test = reader.readLine();

解决方案 »

  1.   

    java.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    String s=br.readLine();
    这里可以读入一行字符,当然包括单个字符啦
      

  2.   

    String ls_Read = "";
    byte[] lb_Read = new byte[100];
    System.in.read(lb_Read);
    for(int i = 0;i < lb_Read.length; i++)
    {
       char c = (char)lb_Read[i];
       if(c == 10 || c == 13) break;
       ls_Read += c;
    }
    return ls_Read;
      

  3.   

    正确解答:
        1。  只读一个字符:
              char a;
              try{
                a = (char)System.in.read(); 
              }catch(IOException ex){
              
              }
        
      

  4.   

    2 。用BufferedReader读
             BufferedReader is = new BufferedReader(new InputStreamReader(System.in));
      

  5.   

    看看这个小例子就OK了:import java.io.*;
    public class p14
    {
    public static void main(String[] args) 
    {
    char c=0;   
    System.out.print("enter a letter:");    //输出语句
        try{   //try{}到catchcatch(IOException e){};是例外处理
    c=(char)System.in.read();   //输出语句
    }catch(IOException e){};
    System.out.println("the letter is:"+c);    //输出语句
    }
    }
      

  6.   

    我的代码import java.io.*;
    public class c
    {
    public static void main(String[] args) 
    {
    try{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String test = reader.readLine();}
    catch(Exception ex)
    {
    System.out.println(ex);
    }     System.out.println(test);
    }
    }显示错误:
    c.java:14: cannot resolve symbol
    symbol  : variable test
    location: class c
                System.out.println(test);
                                   ^
    1 error
      

  7.   

    //将test定义在try块之外,如果定义在try块内的话,出了try块就不可知了
    import java.io.*;public class c
    {
    public static void main(String[] args) 
    {
    String test=null; try{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            test = reader.readLine();}
    catch(Exception ex)
    {
    System.out.println(ex);
    }     System.out.println(test);
    }
    }
      

  8.   

    String test 放在try-catch块外面呀.作用域不对.