-4
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");
}
}
我不知道爲什麼new不等於new。java中的nextLine()無法得到我想要的精確值
請給我一些提示:)
比較字符串與等號是好的,而不是使用== == – SacJn
比較內存分配位置,而String.equals(anotherString)比較記憶存儲的值。 –