这是我的工作代码。但是,一个小问题。我似乎无法输入正确的答案。代码总是只重复"不正确。错误答案......"即使我输入的答案是" slowbro"," Slowbro"和" SLOWBRO"。如果有人可以帮我修改以下代码,我将非常感激:
public void PokemonQuiz ()
{
char again = 'y';
while (again == 'y' || again == 'Y') {
String ans = IBIO.inputString ("\nUnscramble: OBORSLW (Hint: Shelder latches onto its tail.) ");
int tries = 0;
while (ans != "slowbro" || ans != "Slowbro" || ans != "SLOWBRO") {
System.out.println ("Incorrect. Wrong answer. Try again.");
tries++;
ans = IBIO.inputString ("\nUnscramble: OBORSLW (Hint: Shelder latches onto its tail.) ");
if (tries > 3)
{
System.out.println ("The correct answer was SLOWBRO.");
again = IBIO.inputChar ("Play again? (y/n) ");
if (again != 'y' || again != 'Y')
break;
}
}
System.out.println ("Correct.");
}
编辑:我知道" =="应替换为" .equals()"但那我怎么会改变"!=" ??