【发布时间】:2018-02-25 00:03:54
【问题描述】:
对不起,我有一个简单的问题。我试图弄清楚为什么当用户在第一个提示输入动物然后在第二个提示输入是时程序不会打印出“你的项目是一只驼鹿”。任何帮助都会非常感谢
public static void main(String[] args) {
// TODO Auto-generated method stub
String Answer1;
String Answer2;
// Read in how much cash the user has
Answer1 = JOptionPane.showInputDialog("Question 1: Is it an animal, vegetable, or mineral");
Answer2 = JOptionPane.showInputDialog("Question 2: Is it bigger than a breadbox");
if (Answer1 == "animal" && Answer2 == "yes") {
JOptionPane.showMessageDialog(null, "Your item is: A Moose");
}
}
}
【问题讨论】:
-
查看 String.equals 的 Javadoc。您不能使用 == 运算符比较字符串内容。
标签: java string input joptionpane