Question: The following method attempts to return the median (middle) of three integer values, but it contains logic errors. In what cases does the method return
The following method attempts to return the median (middle) of three integer values, but it contains logic errors. In what cases does the method return an incorrect result? How can the code be fixed?

public static int medianof3 (int n1, int n2, int n3) { if (nl < n2) { if (n2 < n3) { return n2; } else { return n3; } else { if (nl < n3) { return n1; } else { return n3;
Step by Step Solution
3.33 Rating (159 Votes )
There are 3 Steps involved in it
The medianOf3 code fails when n3 is the smallest of the three numbers for example when the par... View full answer
Get step-by-step solutions from verified subject matter experts
