The following method attempts to return the median (middle) of three integer values, but it contains logic

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 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;

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Building Java Programs A Back To Basics Approach

ISBN: 9780135471944

5th Edition

Authors: Stuart Reges, Marty Stepp

Question Posted: