[英]Scanner not taking input when use “try {} catch (Exception e) {}”
For some reason when I use try
and catch with this scanner it instantly jumps to the catch
without even taking the input within try {}
出于某种原因,当我在此扫描器中使用
try
和 catch 时,它会立即跳转到catch
处,甚至无需在try {}
中获取输入
This code is supposed to check if the input happens to be a different type other than int此代码应该检查输入是否恰好是 int 以外的其他类型
I seemed to have forgotten to clarify that the code works when I remove the try
and catch
当我删除
try
和catch
时,我似乎忘记澄清代码是否有效
int mapsehen;
try {
mapsehen = scanner.nextInt();
if (mapsehen == 1) {
DrawMap();
}
} catch (Exception e) {
System.out.println("Something went wrong.");
}
Scanner scanner = new Scanner(System.in); // Create a Scanner object
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.