这段Java代码为什么不能正确运行?if语句总是被读取为False,无论输入是什么,包括Anish和“Anish”,输出始终为4。此外,这可能是一个重复的问题。Strings in Java : equals vs ==
import java.util.Scanner;
public class lkjlj {
public static void main(String args []) {
Scanner Pillai = new Scanner(System.in);
System.out.println("Enter Your name");
String nabeel = Pillai.nextLine();
System.out.println(nabeel);
if (nabeel == "Anish") {
System.out.println("Your Age is 6");
} else {
System.out.println("Your age is 4");
}
}
}