This question already has an answer here:
- How do I compare strings in Java? 23 answers
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