【发布时间】:2015-03-29 07:28:19
【问题描述】:
我有一种方法可以通过传入studentarray 和topStudentIndexas 参数来计算一组学生中的下一个最高分,这是由我主要的topStudentIndex 的另一种方法计算的。
下面是我的方法:
public static int calNextHighestOverallStudentIndex(Student[] st, int topStudentIndex) {
double nextHighestOverall= 0;
int secondHighestStudentIndex = 0;
for (int i = 0; i < st.length; i++) {
if ((st[i] != null) && (!(st[i].getStudentIndex() == topStudentIndex))) {
System.out.println(topStudentIndex+ " compare with i = "+i);
double currentOverall= st[i].getOverall();
if (currentOverall> nextHighestOverall) {
nextHighestOverall= currentOverall;
secondHighestStudentIndex = i;
}
}
}
return secondHighestStudentIndex ;
}
我取优等生的索引位置,并检查数组位置是否为空&&相同的索引。如果没有,检查将继续。
但是,输出显示索引位置的比较不起作用。
1 compare with i = 0
1 compare with i = 1
1 compare with i = 2
1 compare with i = 3
1 compare with i = 4
1 compare with i = 5
1 compare with i = 6
我尝试过使用!=和我目前的检查方式,但无济于事。
【问题讨论】:
-
你在比较
st[i].getStudentIndex(),而不是i...
标签: java arrays netbeans integer compare