我做了這個方法,它接受一個數組數組,並且應該返回數組中最頻繁的數組,但它只打印一個[0],這意味着我的一個表達式不會被評估。我不明白哪些和爲什麼。陣列數組的最頻繁陣列
private static int[] frequency(int[][] a) {
for (int z = 0; z < a.length; z++) {
for (int t = 0; t < a[1].length; t++) {
System.out.print(a[z][t]+" ");
}System.out.println();}
int count = 1, tempCount;
int[] popular = a[0];
int[] temp;
for (int i = 0; i < a.length; i++) {
temp = a[i];
tempCount = 0;
for (int j = 0; j < a.length; j++) {
if ((temp == a[j])&&(i!=j)) {
tempCount++;
}
}
if (tempCount > count) {
popular = temp;
count = tempCount;
}
}
return popular;
}
替換了你試過的[z] .length? – mac10688