0
我正在爲德國即將舉行的選舉編寫一個小小的選舉計劃。那麼,它不工作。使用JOptionPane的Java選舉程序
public static void main(String[] args)
{
String _Kandidat1;
String _Kandidat2;
_Kandidat1 = JOptionPane.showInputDialog("Do you Vote for the AFD or for the CDU ?");
if (_Kandidat1 == "AFD")
System.out.println("The AFD won the election!");
else
System.out.println("The CDU won the election!");
}
}
如果我輸入「AFD」它說CDU贏了。如果我在任何情況下輸入「CDU」。 我不確定,但我認爲這個錯誤在if (_Kandidat1 == "AFD")
任何解決方案?
使用'.equals()'方法 – XtremeBaumer