Working on a program where we need separate methods to find the highest and second highest numbers. My code finds the highest number just fine but I can't figure out how to find the second highest number.
public static int highestNumber(int []array1) {
int max = -999999;
for (int i = 1; i < array1.length; i++) {
if (array1[i] > max) {
max = array1[i];
}
}
return max;
}
public static int secondHighest(int []array1) {
int highest= highestNumber(array1);
int secondHighest = array1[0];
for (int i=1; i<array1.length; i++){
if(array1[i]> highest && array1[i] secondHighest);
secondHighest=array1[i];
}
return secondHighest;
}