我提示用户输入一个整数,如果他们没有输入正确的整数(作为对选项的引用),那么我希望提示再次出现,直到他们输入。
到目前为止,这是我拥有的代码:
int logIn = 0;
do {
logIn = Integer.parseInt(JOptionPane.showInputDialog(null,
"Please:"
+ "\n(Enter number value of option you would like to choose.)\n"
+ "\n1. Log In \n2. Register"));
} while (1 > logIn || logIn < 2);
int custIndex;
if (logIn == 1) {
custIndex = recommend.getCustomerIndex();
} else {
customers.printCustomers();
custIndex = customers.readCustomers().size();
}
int options = 0;
do {
options = Integer.parseInt(JOptionPane.showInputDialog(null,
"Would you like to:"
+ "\n(Enter number value of option you would like to choose.)\n"
+ "\n1. See your recommendations. \n2. See top rated books."
+ "\n3. See random books of the day. \n4. Exit."));
} while (1 > options || options < 4);
唯一的问题是我的应用程序无法正确通过登录。如果用户输入 1,它会再次向他们显示提示;如果用户输入任何大于 2 的数字,无论如何都会将他们带到第二个选项。
任何帮助,将不胜感激。