【问题标题】:Check in if is switch case choosen检查是否选择了 switch case
【发布时间】:2020-06-30 18:15:34
【问题描述】:

我如何检查是否选择案例(例如 3 )来继续故事? 我用java写了这个,我会详细介绍故事,但我不知道我该怎么做。我想我可以将案例相互嵌套,但如果我可以选择选项(scanner.nextInt();)也可以添加它们。我认为如果声明会更好,但我不知道如何检查它。我必须补充一点,在发布之前没有找到这个问题的任何答案。感谢您的审查,祝您有美好的一天

             int choice_1 = scanner.nextInt();
        switch(choice_1)
        {
            case 1:
                System.out.println("Guard: Its a honor to meet u sir.Its a pleasure to let You through \nBut do u have coin pass?");
                if(pass==1){
                    ending();
                }
                else{"You should get coin pass first. I am sure that wont be a problem for Prince *laughs*"}
                break;
            case 2:
                System.out.println("*Guard immediately avoided attack and attack u harder that u excepted");
                playerHp = playerHp -30;
                playerArmorHp = playerArmorHp - 50;
                break;

            case 3:
                System.out.println("Guard : Goodbye Sir");
                plan();
                break;
            default:
                System.out.println("Guard is impatient of your not telling anything.Choose option before making him mad.\n"+line);
                break;
        }
        if(switch ( case:3)){
            System.out.println("Do u have coin pass?");
            int pass = scanner.nextInt();
        }

【问题讨论】:

    标签: java if-statement switch-statement


    【解决方案1】:

    您可以将 if 子句更改为 if(choice_1 == 3) 以获得您想要的。

    【讨论】:

    • 谢谢兄弟,我非常需要这个。谢谢:)))
    猜你喜欢
    • 2021-09-09
    • 1970-01-01
    • 2021-01-17
    • 2012-01-07
    • 1970-01-01
    • 2014-03-28
    • 2012-12-28
    • 2021-07-10
    • 1970-01-01
    相关资源
    最近更新 更多