每次从输入流中读取一个数据 保存在ID 这个整型变量中 为什么执行有错误 编译能通过
byte a[]=new byte[10];
    
        try{
        System.in.read(a);
        }
        catch(Exception e){}
     
        id=Integer.parseInt(new String(a));

解决方案 »

  1.   

    错误在于Integer.parseInt(new String(a));
    因为你前面定义的byte的大小为10.在new String(a)时,后面并没有填满,除非你每次输入10位数即可。
    或者截取你输入的位数你要记得给分啊
      

  2.   

    int a = 0;
        
            try{
             a = System.in.read();
            }
            catch(Exception e){}
         
            id=Integer.parseInt(new String(a));