【发布时间】:2015-03-29 07:50:45
【问题描述】:
下面是一个方法,它接受studentarray 和topStudentIndex 的值,该值是由之前的另一种方法计算得出的。
我的数组中有多个对象。但是for循环只循环了一次,直接返回了第一个值。
我不知道为什么 for 循环停止了,即使我的 st.length 超过了
public static int computeNextHighestOverallStudentIndex(Student[] st, int topStudentIndex) {
double nextHighestOverall= 0;
int nextHighestStudentIndex = 0;
for (int i = 0; i < st.length; i++) {
if ((st[i] != null) && (!(i == topStudentIndex))){
double studentOverall = st[nextHighestStudentIndex ].getOverall();
if (studentOverall > nextHighestOverall) {
nextHighestOverall= studentOverall;
nextHighestStudentIndex = i;
}
}
}
return nextHighestStudentIndex ;
}
【问题讨论】:
标签: java arrays for-loop netbeans