您的位置:首页 > 其它

查找第二大值

2015-10-11 00:00 141 查看
public class SecondBig {

public static void main(String[] args) {
int a[] = {9,8,7,7,8,8};
int firstB = a[0];
int secondB = a[1];
for(int i = 1; i<a.length; i++){
if(a[i] > firstB){
secondB = firstB;
firstB = a[i];
}
else if((a[i] < firstB)&&(a[i] > secondB)){
secondB = a[i];
}
}
if(firstB == secondB){
System.out.println("no secondB");
}
else
System.out.println("SecondB is " + secondB);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: