我的方法逻辑有问题吗?

时间:2015-05-29 03:44:52

标签: java methods logic

这里是如果输入为yes则调用方法的代码,如果输入是其他任何内容则表示无效选择。

private static void continueyn()
    {
        String option;
        Scanner input = new Scanner(System.in);
        System.out.println("Continue using program? type in yes or no");
        option = input.nextLine();
        if (option == "yes" || option == "Yes" || option == "YES" || option == "Y" || option == "y")
        {
            printmenu();
            menusystem();
        }
        else
        {
            System.out.println("Invalid answer");
        }

    }

然而,无论何时我输入yes,y,fdjs,f fisj,基本上都是什么,它会说"无效的选择"。

我正在尝试制作一个菜单系统,在使用该方法后继续,但我不知道如何使它正确的方式,这就是为什么我使用此功能并将其放在每个开关案例方法下。

0 个答案:

没有答案
相关问题