java在多维数组中比较rown
我有两个数组——一个多维数组,其中列描述答案,行描述学生。第二个是答案正确的解数组。 我需要编写一个方法来查找哪些行有相同的错误答案(某种反作弊),该方法返回多维数组,其中索引表示学生,以及每个子数组列表 所有错误答案与该指数相同的学生的指数
以下是我如何尝试做到这一点: int num-表示阈值,用于计算错误答案
public static int[][] findSimilarAnswers(int num,char[][] responses,char[] solutions){
int[][] stats = new int[responses.length][];
for (int i = 0; i < responses.length; i++) {
int length = numMatches(responses,solutions,i,num);
int[] wrongs = new int[length];
for (int j = 0; j < wrongs.length; j++) {
wrongs[j] = numWrongSimilar(responses[i],responses[i],solutions);
}
stats[i] = wrongs;
}
return stats;
}
方法numWrongSimilar
比较两个数组的错误答案,并返回错误答案的数量:
public static int numWrongSimilar(char[]studentOneResponse,char[]studentTwoResponse,char[] solutions){
int wrong = 0;
for (int i = 0; i < solutions.length; i++) {
if(studentOneResponse[i] != solutions[i]
&& studentOneResponse[i] == studentTwoResponse[i])
wrong++;
}
return wrong;
}
方法numMatches
找出哪些错误答案高于阈值
下面是一系列回应和解决方案
char[][] responses = { {'C', 'A', 'B', 'B', 'C', 'A'},
{'A', 'A', 'B', 'B', 'B', 'B'},
{'C', 'B', 'A', 'B', 'C', 'A'},
{'A', 'B', 'A', 'B', 'B', 'B'}
};
char[] solutions = {'C', 'A', 'B', 'B', 'C', 'C'};
使用这个数组和阈值3
它必须返回
[[], [3], [], [1]]
但它返回[[], [3], [], [5]]
好像我写错了wrongs[j] = numWrongSimilar(responses[i],responses[i],solutions);
但我该如何正确地重写它呢
共 (0) 个答案