【发布时间】:2023-03-29 08:00:01
【问题描述】:
我正在尝试使用通过 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") || .... -
非常感谢,我的朋友!