0
int modeOdd = 0;
System.out.println("Occurence of all existing ODD digits --");
for (int i = 1; i < ary.length; i += 2) { // This prints the array element at the odd indices
if (ary[i] > 0) {
System.out.println("Digit " + i + " : " + ary[i]);
}
}
System.out.println("\nthe odd digit (s) that has/have the "
+ "higest occurence-");
for (int i = 1; i < ary.length; i += 2){
int newNumber = ary[i];
if (newNumber > ary[modeOdd]) && (i % 2 != 0)){
modeOdd = i;
}
}
System.out.println(modeOdd);
}
该代码的第一部分工作并打印奇数索引处的数组元素。然而,代码的第二部分是找到我所有数组元素的模式。我不明白为什么它会这样做,因为我在索引i处开始它,并将其增加2.我试着模数2不能等于0,也看不到任何更改。如何在一个数组中搜索奇数索引元素
我需要改变什么?谢谢。