用户输入后循环菜单

时间:2017-11-24 16:08:48

标签: java

filter

我希望播放器在按下2之后返回主菜单。只知道基本的java并且只是寻找快速解决方案,没有任何复杂的东西。与循环有关。 任何帮助表示赞赏谢谢:)。

1 个答案:

答案 0 :(得分:0)

您必须添加do-while块:

int menuChoice = -1;
do {

    //....

    menuChoice = scan.nextInt();

    switch(menuChoice)
    {
        case 1:System.out.println("Loading Zest Quest");
        break;
        case 2:System.out.println("This is a text based game.It is based on player choice.Your choices will matter so choose carefully");
                    System.out.println("You can interact with items and objects by typing examine,pick up,attack and other words.");
                    System.out.println("If you are having any trouble with a spefic parts check the cheat sheet provided.");enter code here
                    System.out.println("");
        break;
        case 3:System.out.println("Goodbye my friend");
    }

} while(menuChoice != 3);