0

here is the code that calls a method if input is yes and says invalid selection if input is anything else.

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");
        }

    }

However, whenever i type yes,y,fdjs,f fisj, bascically anything, it says "invalid selection".

I am trying to make a menu system that continues after using the method but i dont know how to make it the right way so that is why i am using this function and putting it under every switch case method.

SadJavaBoi
  • 69
  • 1
  • 7
  • use String.equals method. Read this to understand diff between equal and == http://stackoverflow.com/questions/1643067/whats-the-difference-between-equals-and – Sachin Gupta May 29 '15 at 03:46
  • gotcya. forgot about that. – SadJavaBoi May 29 '15 at 03:49
  • == tests for reference equality. .equals() tests for value equality. Consequently, if you actually want to test whether two strings have the same value you should use .equals(). – Avyaan May 29 '15 at 05:23

0 Answers0