mercredi 21 décembre 2016

Java: Why does this if statement never resolve to true? [duplicate]

This question already has an answer here:

I'm trying to make a noughts and crosses prototype and I'm struggling with this section. This section of code is getting user input, and if the input is y, it should change the gamestate to 0 which restarts the game. However this doesn't happen, can anyone explain why?

Scanner s = new Scanner(System.in);
                System.out.println("Would you like to play again?");
                if (s.next().toLowerCase() == "y") {
                    System.out.println("Okay");
                    g.gamestate = 0;
                } else {
                    g.gamestate = 4;
                }

Aucun commentaire:

Enregistrer un commentaire