这种方式输入的是字符,我现在需要直接输入数字。
byte buf[]=new byte[10];
try{
  System.in.read(buf);
}catch(Exception e){
  System.out.println("catch error");
}

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/288/288311.shtm 中有详细的说明,请参考。
      

  2.   

    使用DataInputStream类。
    int aaa;
    DataInputStream keybord=new DataInputStream(System.in);
    try{
       aaa=keybord.readInt();
    }
    catch(IOException e){}
      

  3.   

    public class test {
      public static void main(String[] args) {
        int a;
        if (args.length > 0) 
          a = Integer.parseInt(args[0]);
      }
    }在命令行中输入数值后,可以在程序中得到
      

  4.   

    不戒和尚,搞不定啊,
    import java.io.*;public class Jtest
    {
    public static void main (String args[])
    {
    int aaa=0;
    System.out.print("Input a num:");

    DataInputStream keybord=new DataInputStream(System.in);
    try{
       aaa=keybord.readInt();
    }catch(IOException e){}
    System.out.println("The num is:"+aaa);
    }
    }
    运行结果:
    Input a num:12
    The num is:825363722这是什么值?搞不定!
      

  5.   

    雷老虎,thank you!你看这样行不行?import java.io.*;public class Jtest
    {
    public static void main (String args[])
    {
    System.out.print("Input a num:");

    int choice;
    byte buf[]=new byte[10];
    try{
    System.in.read(buf);
    }catch(Exception e){
    System.out.println("catch error");
    }
    String str=new String(buf);
    //System.out.println("str=" + str.trim());
    choice=Integer.parseInt(str.trim());
    System.out.println("The num is:"+choice);
    }
    }
    运行结果:
    Input a num:1564798
    The num is:1564798
      

  6.   

    这样可以,但是不好,原因已经说过了,推荐使用BufferedInputReader并用readline,你这样的话如果用户输入超过10个字符,在下一次调用in.read()时会出问题。
      

  7.   

    readline好象已经被禁止了,我想也可以使用System.out.flush();吧?
      

  8.   

    没有被禁止吧,你从哪儿看到的?
    out.flush()是把输出缓冲区的内容全部写入目标,在这里怎么用呢?
      

  9.   

    那要看从那里得到了
    网络上的byte array可以用DataInputStream
    如果是命令行的话,用Integer.parseInt(String)不就可以吗?