【发布时间】:2014-02-05 18:20:06
【问题描述】:
所以,由于某种原因,我在使用字符串输入时遇到了问题。
我不知道为什么。也许这是每个人都知道的非常愚蠢的事情,但我不知道。
这是无效的代码:
import javax.swing.*;
public class Thing {
public static void main(String[] args) {
String input;
JOptionPane.showMessageDialog(null,"Welcome to the test...");
input = JOptionPane.showInputDialog("Do you wish to take the tutorial?" + "\n" +
"If affirmative, enter 'Yes'");
String i = input;
if(i == "Yes") {
tutorial();
} else if(input=="'Yes'") {
JOptionPane.showMessageDialog(null,"Don't actually put apostraphes around you're answer.");
tutorial();
} else {
JOptionPane.showMessageDialog(null,"Remember, you can pull up the tutorial at any time with 'T'");
}
}
是的,实际上我在其他地方确实有一个教程方法,而且效果很好。
主要问题是,如果我输入'Yes'或Yes,它仍然会进入最后的else。
我只放了
String i = input;
并从
if(input == "Yes") {
因为那时它也不起作用。
那我做错了什么?
【问题讨论】:
标签: java eclipse string comparison