试图返回最高分,但它返回了错误的分数......不确定问题是什么,如果我将数组列表中的第一个对象设置为最高分,然后将其与之进行比较?
public String findHighest () {
Student newStu;
Student s;
int highest;
s=collegeList.get(0);
highest=s.getQuizScore();
for (int i=1; i<collegeList.size() ;i++ ) {
newStu=collegeList.get(i);
if (highest>newStu.getQuizScore()){
highest=newStu.getQuizScore();
return newStu.toString();
}
}
}
public String findHighest () {
Student newStu;
Student s;
int highest;
s=collegeList.get(0);
highest=s.getQuizScore();
for (int i = 1; i < collegeList.size(); i++) {
newStu = collegeList.get(i);
if (highest < newStu.getQuizScore()){
highest = newStu.getQuizScore();
}
}
return newStu.toString();
}
//试过这个,它一直说newStu可能没有被初始化......