Question: Write a method that returns the median value in the array. If the length of the array is odd, the median is the value in

Write a method that returns the median value in the array.

If the length of the array is odd, the median is the value in the center of the array.

If the length of the array is even, the median is the average of the two numbers in the center.

You may assume the array passed into this method will never be empty.

Hint: Weve imported java.util.* for you in the Unit Test, so you have a handy static method on Arrays that you can use called Arrays.sort. Note: There are no imports in the Scratchpad if you would like to use that for extra testing.

public double median(int[] arr) { return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!