【发布时间】:2012-06-15 13:11:46
【问题描述】:
// Find smallest year
int pastMin=0;
int currentMin=ontarioBankInfoInt.get(0);
int currentMinIndex=0;
int reps=(ontarioBankInfoInt.size()-1)/3;
for(int x=0; x<=reps; x++){
for (int i=0; i<ontarioBankInfoInt.size()-1; i++){
if (ontarioBankInfoInt.get(i)<currentMin){
if (ontarioBankInfoInt.get(i)>pastMin){
currentMin = ontarioBankInfoInt.get(i);
currentMinIndex = i;
pastMin = currentMin;
}//If End
}//If End
}//For End
//Add other information
yearArray.add(currentMin);
}//For End
注意:reps 是它需要找到的年数。 这段代码的目的是在 arrayList 中搜索最小的年份,然后将其添加到“yearArray”中,然后找到下一个最小的 add 将其添加到 say 数组中,冲洗并重复,直到它遍历整个数组。
我的问题是它总是在同一年返回,我不确定为什么有任何帮助?
谢谢
【问题讨论】:
-
您不使用
Collections.sort的任何特殊原因?这是作业吗? -
我推荐使用
for(int i:ontarioBankInfoInt)。这样你就可以在循环中使用i而不是ontarioBankInfoInt.get(i)