- 在调用了nextInt()后,我们可以先调用一次nextLine(),将该行剩下的内容抛弃;
int option = input.nextInt();
input.nextLine(); // Consume newline left-over
String str1 = input.nextLine();
- 全部都使用nextLine()读入,然后将其读入的数据转换为Integer。
int option = 0;
try {
option = Integer.parseInt(input.nextLine());
} catch (NumberFormatException e) {
e.printStackTrace();
}
String str1 = input.nextLine();