public  void input(){
                 int command;
while(true){
try {
command = System.in.read();
if(command==1){
break;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我输入的是1,可是读进来的却是49。该怎么样才能正确的读取我输入的数字?

解决方案 »

  1.   

    49是 1的ascii对应值你把49强转成char类型 就是1了 
      

  2.   

    For Example:public  void input(){
                     int command;
            while(true){
                try {
                    command = System.in.read();
                    if((char)command=='1'){//注意这行
                        break;
                    }
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
      

  3.   

    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();