这基本上是我从用户输入的数字与"int“进行比较的相同之处,但出于某种原因,它不适用于字符串数组中的单词,即使它是正确的。它还没完成,我只想把它作适当的比较。
case 2:
cell = (int)((Math.random() * 59) + 1);
System.out.println(englishNumbers[cell]);
System.out.println("what is the number? >");
String w = in.nextLine();
if(w != frenchNumbers[cell])
{
System.out.println("That is incorrect");
numChoice(2);
}
else
{
System.out.println("That's correct");
numChoice(2);
}
break;发布于 2015-12-27 06:36:12
使用if(!w.equals(frenchNumbers[cell]))
而不是
if(w != frenchNumbers[cell])。
您必须比较值,而不是引用。
https://stackoverflow.com/questions/34478177
复制相似问题