我想使用通过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