我在下面的代码中使用了一个 while(true) 循环,但我们已经停止使用它了。我想不出另一种方法来做到这一点。
我试过使用 do-while 循环,但这对我的情况没有帮助。
'''java
while(true){
System.out.println("\nSelect the number of the Option you wish to carry out:\n 1) Enter Scores\n 2) Find Golfer\n 3) Display Scoreboard\n 4) Edit Scoresheet\n 5) Exit\n ");
userChoice = integerVerify(); //Used to verify whether user input is a valid number
switch (userChoice) {
case 1:
System.out.println("Please enter the scores in the following order");
displayPlayers(); //Displays scoreboard to help users enter player scores in order.
addScores(); //Used to verify whether user input is a valid String
break;
case 2:
System.out.println("**********PLEASE ENTER THE NAME OF THE PLAYER YOU WISH TO FIND**********");
findPlayer();
break;
case 3:
displayPlayers();
break;
case 4:
options();
break;
case 5:
System.out.println("Are you sure you wish to exit?");
confirm = stringVerify();
if (confirm.equalsIgnoreCase("yes") || confirm.equalsIgnoreCase("y")) {
System.out.println("Thank you for using our application.");
System.out.println("Exiting");
System.exit(0);
}
break;
default:
System.out.println("Please enter an appropriate option.");
}
}
'''
代码需要拒绝任何不在 switch-case 中的东西......但它还需要显示适当的消息,无论是通过函数还是来自循环本身,最终,我仍然需要它循环直到退出选项(案例 5)被输入。
RISEBY
相关分类