- Feb 3, 2005
- 7,326
- 2
- 76
I'm trying to write code that takes three integers and returns the median of those values. Here is what I have so far (I think it's correct, though it may not be):
public static int median(int x, int y, int z) {
if (x > y && x > z)
if (y > z)
return y;
else
return z;
if (x > y && x < z)
return x;
if (x < y && x < z)
if (y > z)
return z;
else
return y;
}
When compiling, I keep getting one error: Missing return statement {
I'm still new to Java, so I'm not sure what I'm missing here.
public static int median(int x, int y, int z) {
if (x > y && x > z)
if (y > z)
return y;
else
return z;
if (x > y && x < z)
return x;
if (x < y && x < z)
if (y > z)
return z;
else
return y;
}
When compiling, I keep getting one error: Missing return statement {
I'm still new to Java, so I'm not sure what I'm missing here.