我想使用通過JOptionPane獲得的字符串的值。但是,讀取字符串時出現問題。我在這裏做錯了什麼?JOptionPane不能讀取字符串
import javax.swing.JOptionPane;
public class convertNumber123 {
public static void main(String[] args){
String numsystem1;
numsystem1 = JOptionPane.showInputDialog("Please enter the numeral system that you want to convert from: binary, octal, decimal or hexadecimal.");
if (numsystem1 == "Binary" || numsystem1 == "Octal" || numsystem1 == "Decimal" || numsystem1 == "Hexadecimal")
System.out.println (numsystem1 + "it is!");
else
System.out.println ("Please, enter the correct system name.");
}
}
您的問題將很快關閉......但您無法將字符串與'=='進行比較,您必須使用'.equals()'方法。所以像這樣......'numsystem1.equalsIgnoreCase(「Binary」)|| ....' – 3kings
非常感謝,我的朋友! – daniilcul8r