import java.util.Scanner;
public class NewClass {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name");
String name = scanner.nextLine();
System.out.println("Is "+ name + " really your name?");
String answer1 = scanner.nextLine();
if (answer1 == "yes"){
System.out.println("Alright ");
}else {System.out.println("Liar!");
}
}
}
Liar!
即使我输入了它也会输出yes
,所以answer1
等于yes
。为什么?