我正在尝试用case语句,似乎在某个地方创建了一个无限循环。我不知道为什么会这样。我的代码反复循环一次,而不是再次循环并询问另一个计算的选项-它不断打印出“无法识别的选项...”
有人能对此有所启发吗?
这是我的代码。
public static void main(String []args) {
char choice;
boolean exit = false;
UserInterface userMain = new UserInterface();
do {
choice = userMain.menuUI();
switch(choice) {
case 'q':
exit = true;
break;
case 'r':
Real realResult = realCalculation();
System.out.println("\nAnswer = " + realResult.toString() + "\n");
break;
case 'c':
Complex complexResult = complexCalculation();
System.out.println("\nAnswer = " + complexResult.toString() + "\n");
break;
default:
System.out.println("\nUnrecognised option.\n");
break;
}
} while (exit == false);
System.exit(0);
}
只能是因为userMain.menuUI();
从不返回q或Q
如果您想了解更多详细信息,则必须提供相应的代码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句