希望能给出几个方法,多谢!

解决方案 »

  1.   

    最简单的:
     BufferedReader br = 
                new BufferedReader(
                    new InputStreamReader(System.in));
            String s=in.readLine();
          //从输入流in中读入一行,并将读取的值赋值给字符串变量s
          System.out.println("Input value is: "+s);
          int i = Integer.parseInt(s);//转换成int型
    JDK1.5 中新提供的:
     Scanner sc = new Scanner(System.in);
            int i = sc.nextInt();
      

  2.   

    public static int readInteger()
        {
            int a=0,b=0;
            boolean done=false;        while(!done)
            {
                try
                {
                    a=(int)System.in.read();
                    if(a<0||(char)a=='\n')
                        done=true;
                    else if((char)a!='\r')
                    {
                        a-=48;
                        b=b*10+a;
                    }
                }
                catch(java.io.IOException e)
                {
                }
            }
            return b;
        }
    不知道这个算不算,一次可以读一位整数。
      

  3.   

    还有一个:
    System.read.in(buf,0,24);
    String str=new String(buf);
    也可以从键盘读入字节。