Sorry if the question doesn't make much sense, I'm very new to Java. So here's my problem: I'm making a text adventure game (very basic at the moment) and I created a string (choice1), which is equal to the answer the player gives to a question the game asks. The answer is either supposed to be north, North, south or South. When I found that no matter what I typed it said it was an invalid answer, I made the game display what choice1 was equal to when I typed my answer. I found that when I typed north, it displayed north, when I typed south, south, etc. So it had correctly picked up what I had typed, but it still said it was an invalid answer. Here is my code (including the part that displays what choice1 is equal to):
Scanner answer = new Scanner(in);
String choice1 = answer.nextLine();
out.println(choice1);
if (choice1 == "north" || choice1 == "North") //If the answer is North
{
out.println("You start walking towards the mountains in the distance. A cold wind picks up from behind you.");
}
else if (choice1 == "south" || choice1 == "South") //If the answer is south
{
out.println("You head into the forest and are quickly surrounded by trees. Patches of light dance on the floor to the whim");
}
else if (choice1 != "south" || choice1 != "South" || choice1 != "north" || choice1 != "North") //invalid answer
{
out.println("Please enter a valid answer.");
}
answer.close();