嗨我试图找到使用嵌套for循环两个字符串数组之间的匹配。然而它似乎已经环绕了更多次。比较两个字符串数组与嵌套For循环
for(int i = 0; i < ca; i++) //ca contains 10
{
for(int j = 0; j < ra; j++) //ra contains 10
{
if(cAnswers[i].equals(rAnswers[j]))
{
count++; //Increments count to indicate a match
System.out.println("The current count: " + count); //To check the count
}
}
}
System.out.println("The number of correct questions is " + count + "/10"); //The result currently gives me 50/10 no matter what.
我尝试使用< =,而不是仅仅<,但最终得到一个索引越界。
什么是cAnswers和rAnswers的可能值?这似乎与MCQ类型的答案类似。如果是这样,一旦cAnswers [i]匹配一些东西,你不应该从内部循环中跳出来并转到下一个cAnswers? – devang
你的比赛是否需要在同一个索引或无所谓? – jlordo