如何让我的程序提示用户做出不同的选择,直到他们决定有目的地退出程序?现在,我尝试了一个带有名为“exit”的 boolean 值的 do-while 循环,试图说当 exit 为 false 时,不断提示用户选择要做什么,尽管它所做的只是询问一次并在完成之后询问他们用户需要,应用程序停止。
这是我的代码:
boolean exit = false;
do {
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 (logIn < 1 || logIn > 4);
if (options == 1) {
recommend.displayRecommendations(custIndex);
} else if (options == 2) {
calculations.displayTopTen();
} else if (options == 3) {
calculations.displayRandomBooks();
} else if (options == 4) {
exit = true;
System.exit(0);
}
} while (exit = false);
如有任何帮助,我们将不胜感激。
最佳答案
这是你的问题:
while (exit = false);
仔细看非常...
关于java - 'do while' 循环的更多问题,Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9204086/