Don't know why this isn't working

• September 24th, 2013, 04:30 PM
Eucibous
Don't know why this isn't working
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);
}
}
• September 24th, 2013, 04:33 PM
GregBrannon
Re: Don't know why this isn't working
Post your code in formatting tags.

Every one of your if statements ends at the first semi-colon, ';'. Take those out and keep working on it.
• September 24th, 2013, 04:35 PM
Eucibous
Re: Don't know why this isn't working
Aha! It was the semicolons, awesome. Thank you!