【发布时间】:2019-04-08 16:24:59
【问题描述】:
System.out.print("What kind of array do you want to create?\n1. Integer Array\n2. Double Array\n3. String Array\nYour Answer: ");
String input;
int num1 = 0;
try {
input = s.next();
num1 = Integer.parseInt(input);
while (num1 > 3 || num1 < 1) {
System.out.print("Please enter one of the three available options.\nYour Answer: ");
input = s.next();
num1 = Integer.parseInt(input);
}
} catch (InputMismatchException e) {
System.out.println("Do not enter a letter/special character");
}
所以我基本上是在向用户提出一个问题,询问他想要创建什么样的数组。但是,当我尝试打破它并输入Char/String 时,我会遇到错误并退出程序。
【问题讨论】:
-
堆栈跟踪应该指出哪里异常被抛出
标签: java arrays exception-handling java.util.scanner