java中的nextLine()无法获得我想要的确切值
我不知道为什么新不等于新 请给我一些提示:)改用java中的nextLine()无法获得我想要的确切值,java,Java,我不知道为什么新不等于新 请给我一些提示:)改用userInput.equals(“新”) 这就解释了一切:将字符串与等于进行比较比使用===比较内存分配位置更好,而string.equals(另一个字符串)比较内存存储值。它真的很有效!谢谢!! public static void main(String args[]){ System.out.print("Type new, wil display TRUE:"); Scanner sc = new Scanner(Syst
userInput.equals(“新”)
这就解释了一切:将字符串与等于进行比较比使用===比较内存分配位置更好,而string.equals(另一个字符串)比较内存存储值。它真的很有效!谢谢!!
public static void main(String args[]){
System.out.print("Type new, wil display TRUE:");
Scanner sc = new Scanner(System.in);
String userInput = sc.nextLine();
if(userInput=="new"){
System.out.println("TRUE");
}else {
System.out.println("FALSE");
}
}