I'm fairly new to Java and am trying to create a text game, involving escaping. Here is my code:
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class Adventure {
public static void main (String args[]) throws InterruptedException{
System.out.println("YOU WAKE ON YOUR COUCH. YOU NEED TO GET OUT OF YOUR HOUSE.");
int x = 1;
while (x == 1){
Scanner ACTION = new Scanner(System.in);
System.out.println("WHAT DO YOU DO NEXT?");
String action;
action = ACTION.next();
if (action == "a"){
System.out.println("if");
}else{
System.out.println("else");
}
}
}
}
Try running and see that the if does not work, if you enter 'a', it prints 'else'. Please explain each new line of code (if any) in your answer. Thank you.