hasNextInt()
只返回整数。否则检查没有意义。
通过在if语句中调用nextInt()
,再次在正文中调用int row = 0;
while (scan.hasNext() && row < 1 || row > 3) {
String next = scan.next();
try {
row = Integer.parseInt(next);
} catch (NumberFormatException e) {
System.out.println("invalid input " + next);
}
}
,您将读取两个数字。
尝试
qazxswpoi