So I wrote this simple code to find the middle number/median of three numbers. For some reason, it is outputting 300 as the second highest/middle number though I don't see why the code would assign Array1[2] to that variable, since it doesn't meet the requirements. Any help would be appreciated.
public class secondhighest {
public static void main(String[] args) {
// declares an array of integers
int[] Array1 = {150, 75, 300};
int secondhighest;
secondhighest = 0;
// tests integers in array to locate the second highest integer
if (Array1[0] > Array1[1] && Array1[0] < Array1[2]); {
secondhighest = Array1[0];
}
if (Array1[0] > Array1[2] && Array1[0] < Array1[1]); {
secondhighest = Array1[0];
}
if (Array1[1] > Array1[0] && Array1[1] < Array1[2]); {
secondhighest = Array1[1];
}
if (Array1[1] > Array1[2] && Array1[1] < Array1[0]); {
secondhighest = Array1[1];
}
if (Array1[2] > Array1[1] && Array1[2] < Array1[0]); {
secondhighest = Array1[2];
}
if (Array1[2] > Array1[0] && Array1[2] < Array1[1]); {
secondhighest = Array1[2];
}
System.out.println("The second highest number is: " + secondhighest);
}
}