代码改变世界

输出数组中第二个最大的数字

2013-04-13 18:52  呆河马  阅读(446)  评论(0编辑  收藏  举报
int max,nextMax,temp;
for(int num i : numList) {
if(max == null) {
max = i;
} else {
if(max < i) {
nextMax = max;
max = i;
} else {
if( nextMax == null) {
nextMax = i;
} else ( nextMax < i) {
nextMax = i;
}
}
}
}
注:
int a[] = {1, 2, 3, 4, 5};
下面的代码
for(int i : a){
System.out.println(i);
}
等价于
for(int i=0;i<a.length;i++){
System.out.println(a[i]);
}