System.in 这个in就是默认好的读控制台的对象....

解决方案 »

  1.   

    DataInputStream in =
          new DataInputStream(
            new BufferedInputStream(
              new FileInputStream(System.in)));
    while ((in.read()) != -1)
    {
       //dosomething;
    }
      

  2.   

    DataInputStream in =
          new DataInputStream(
            new BufferedInputStream(System.in));
        String s;
        try {
          while((s = in.readLine()).length() != 0)
            System.out.println(s);
          // An empty line terminates the program
        } catch(IOException e) {
          e.printStackTrace();
        }
      

  3.   

    DataInputStream in =
          new DataInputStream(
            new BufferedInputStream(System.in));
      

  4.   

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          String str = br.readLine();
    任何键盘输入数据,都可读出其字符串类型
    然后通过转换,得到其他类型
    比如
    int i = Integer.valueOf(str) ;
    注意,都需要捕捉异常,比如输入字符非数字类型等
      

  5.   

    public class consoleTester {  public consoleTester() {
        System.out.print("pls input:");
        try{
          byte[] b = new byte[10];
          System.in.read(b);
          String s = new String( b );
          System.out.println(s);
          int i = Integer.parseInt(s.trim());
          System.out.println(i);
        }catch(IOException ioe){
          ioe.printStackTrace();
        }
      }
      public static void main(String[] args) {
        consoleTester consoleTester1 = new consoleTester();
      }
    }
      

  6.   

    import java.io.*;
    public class test2{
    public static void main(String[] args){
    DataInputStream in =
          new DataInputStream(
            new BufferedInputStream(System.in));
        String s;
        String a,b;
        String s1="Please input integer ";
        int i=0;
        a="0";
        b="0";
        System.out.print(s1+" a:");
        try {
          while((s = in.readLine()).length() != 0){
            i=i+1;
            if(i==1){ a=s;System.out.print(s1+" b:");}
            if(i==2){ b=s;break;}
          }
          int c=Integer.parseInt(a)+Integer.parseInt(b);
          System.out.print("The result of a+b:"+String.valueOf(c));  
        } catch(Exception e) {
          e.printStackTrace();
        }
     }
    }