Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

Members have full access to the forums. Advertisements are removed for registered users.

# Thread: Don't know why this isn't working

1. ## 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);
}
}

2. ## 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.

3. ## The Following User Says Thank You to GregBrannon For This Useful Post:

Eucibous (September 24th, 2013)

4. ## Re: Don't know why this isn't working

Aha! It was the semicolons, awesome. Thank you!