嗨我只是瞎搞,我不能得到這個工作:對象比較:地址VS內容
public static void main(String[] args){
Scanner input = new Scanner (System.in);
String x = "hey";
System.out.println("What is x?: ");
x = input.nextLine();
System.out.println(x);
if (x == "hello")
System.out.println("hello");
else
System.out.println("goodbye");
}
它當然應該,如果你輸入Hello打印你好你好,但它不會。我使用Eclipse只是爲了解決問題。請稍後快速幫助
這很奇怪,我從來沒有這樣做與掃描儀。這是特定於Eclipse的嗎?大概愚蠢的問題... – Josh
這不是「怪異」,它是事情在Java中完成的方式。它與Eclipse無關;) – Jacob
或null-safe:'「hello」.equals(x)' – pmnt