可能重复:
如何比较 Java 中的字符串?
我对下面的代码有问题;问题是在你第一次不说地图之后No try again
,无论你是否输入“地图”,它都会随着输入框不断重复。
System.out.println("My cousin Diego is in trouble in the Majestic palace. But how do we get there?");
System.out.println("Who do we call when we don't know where to go? Huh? I didn't get that...");
imTheMap=robotMagic.next();
if (imTheMap.equals("map"))
{
System.out.println("That's right!"); //the issue is here
}
else
{
while(imTheMap!=("map"))
{
System.out.println("No! try again");
imTheMap=robotMagic.next();
}
}