我试图弄清楚如何引用 2 个字符串数组的索引。在 checkAnswer 方法中,我可以确认用户输入存储在索引 [i] 处的 capitalArray 但如何比较 capitalArray[i] == stateArray[i] 的索引而不是比较存储在索引 [i] 处的字符串
public static void main{
...
for (int i = 1; i <=10; i++){
System.out.println("What is the capital of " + stateArray[randomQuestion(0)]"?");
answer = in.nextLine();
if (checkAnswer(stateArray, capitalArray, answer) == true)
{
correct++;
}
total = i;
}
}
public static boolean checkAnswer(String[]stateArray, String[]capitalArray, String answer) {
for (int i = 0; i < stateArray.length; i++)
{
if (capitalArray[i].equalsIgnoreCase(answer) && capitalArray[i] == stateArray[i])
{
return true;
}
}
return false;
}