我正在为老虎机模拟器编写一个程序,我的大部分代码都在一个 while 循环中。
System.out.println(" * Choose an option: * ");
System.out.println(" * 1: Display credit count. * ");
System.out.println(" * 2: Play Again. * ");
System.out.println(" * 3: End Game. ");
如果用户选择3结束游戏,他将被引导到结束游戏菜单。在我的循环之外
有一组单独的语句来确定用户是否因为没有积分或选择结束游戏而离开了循环。if
while
//The case in which the user ended the game.
else {
System.out.println("");
System.out.println("You have ended the game. You have finished with a total of: "+credits+" credits!");
System.out.println("");
System.out.println("Next player?");
System.out.println("");
System.out.println("1: Yes, there is another player that would like to start with my "+credits+" credits.");
System.out.println("2: Yes, there is another player, but he will start with 10 credits.");
System.out.println("3: No, End the game.");
selection2 = in.nextInt();
}
我想要做的是:如果用户输入1,它将带他回到主游戏循环的开始。
我知道没有 goto cmd,所以有人知道我该怎么做吗?我被困在一个循环之外,无法重新进入!(我考虑过在一切之外再做一个循环......)