I am trying to ask the user for a simple 'yes' or 'no' response using:
Scanner user = new Scanner( System.in );
String response = user.nextLine();
I am then using the value of 'response' in a series of IF statements to output a specific piece of text.
However every time I enter in a response the program just terminates and I'm not sure what I am doing wrong.
Here's all of the code to make things more clear:
import java.util.Scanner;
public class vedant {
public static void main (String args[]){
System.out.println("Is it past 11.30pm?");
Scanner user = new Scanner( System.in );
String response = user.nextLine();
if (response == "yes") {
System.out.println("tut tut tut...");
user.close();
} else if (response == "no") {
System.out.println("Good boy");
user.close();
}
}
}
BTW I'm new to Java so sorry if this is quite a basic mistake.