以下是我使用的代码:
do {
try {
System.out.println("Please enter the type of employee. (1 - salaried, 2 - hourly, 3 - commissioned)");
type = user_input.nextInt();
letter = true;
}
catch (InputMismatchException e) {
letter = false;
System.out.print("Entered value is not an integer. Try again.");
}
} while (!letter);
发布于 2018-08-17 10:22:33
解决方案:
String type = null;
Scanner user_input = new Scanner(System.in);
boolean letter = true;
do {
try {
System.out.println("Please enter the type of employee. (1 - salaried, 2 - hourly, 3 - commissioned)");
type = user_input.nextLine();
Integer.valueOf(type);
} catch (Throwable e) {
letter = false;
System.out.print("Entered value is not an integer. Try again.");
}
} while (letter);
https://stackoverflow.com/questions/-100002228
复制相似问题