I currently have a game where the user needs to type in the secret code correctly to play the game. However, each time I type in "game" as the user code, it prints out Goodbye!, rather than play the game. Can someone explain why?
public static void secretCode() {
System.out.println("Enter your secret code to play: ");
Scanner passwordInput = new Scanner(System.in);
String userCode = passwordInput.nextLine();
String gameCode = "game";
if (userCode == gameCode) {
System.out.println("Let's begin! Each game costs $50 to play.");
playGame();
System.out.println("Thanks for playing. Goodbye!");
}
if (userCode != gameCode) {
System.out.println("Goodbye!");
}
}