public static int getSecondMax(int[] a) throws Exception {
if(a == null || a.length <=1){
throw new Exception("没有第二大的值");
}
int max1=Integer.MIN_VALUE,max2=Integer.MIN_VALUE;
for (int i = 0; i < a.length; ++i){
if(a[i] == max1){
continue;
}
if (a[i] > max1){
max2 = max1;
max1 = a[i];
} else {
max2 = Math.max(max2, a[i]);
}
}
if(max2 == Integer.MIN_VALUE){
throw new Exception("没有第二大的值");
}
return max2;
}