据我所知,使用nextInt()方法不会消耗新的行字符,所以要处理我需要使用空的nextLine()方法继续前进。
我的问题是,作为一种替代解决方案,程序可以使用两个扫描程序对任何类型的运行时错误开放,一个用于字符串输入,一个用于整数?
Scanner in = new Scanner(System.in);
Scanner ints = new Scanner(System.in);
int userInt = ints.nextInt();
String userInput = in.nextLine();
感谢您的帮助!
(编辑所以问题不那么主观)
答案 0 :(得分:1)
这里的问题是
String userInt = ints.nextInt();
您正在将int值输入到字符串值中 试试
String userInt=ints.next();
//OR
int userInt=ints.nextInt();
回到你的问题 没有它不是“坏”有两个扫描仪,它只是不需要。