我正在尝试使用通过JOptionPane获得的String的值。但是,读取字符串存在问题。我在这里做错了什么?
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.");
}
}
您比较字符串的方式是错误的。在Java中,您必须使用这样的.equals()
方法
if (numsystem1.equals("Binary") || numsystem1.equals("Octal") || numsystem1.equals("Decimal") || numsystem1.equals("Hexadecimal"))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句