【发布时间】:2020-08-04 08:51:29
【问题描述】:
尝试使用扫描仪识别整数和字符串,如果输入了某个字符串,则停止用户输入。
Scanner myObj = new Scanner(System.in);
System.out.println("Enter number of students");
int numberof = myObj.nextInt();
需要这样做,如果用户键入“end”,扫描仪将不再接受用户输入。我不能把行 int numberof = myObj.nextInt();在循环或其他东西中并限制变量范围,因为我在我的其余代码中使用 numberof 的值。
【问题讨论】:
-
如果用户输入“supercalifragilisticexpialidocious”怎么办?提示:你会得到一个例外......
标签: java string integer java.util.scanner