控制台读取数字
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(); } } }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(); } } }
[解决办法]
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();