⌛ Median

Place your code into a file named Median.java.

Write a program that receives one or more numbers as command line parameters, converts them into double-values, and prints out their median in the form “Median: x”, where x is the median of the numbers.

We define median as the number that occurs in the middle when the number are sorted into ascending order. If the number of numbers is even, the median is computed as the mean of the two middle-most numbers.

Example

The first test runs your program as follows:

java Median 58.03125 62.5 75.03125 25.03125 -39.9375 7 -38.75

The expected program output is:

Median: 25.03125

Explanation: the numbers sorted into ascending order are -39.9375, -38.75, 7, 25.03125, 58.03125, 62.5, 75.03125. There are 7 numbers (an odd number) and the median is the middle-most, that is 4th, number 25.03125.

The second test runs your program as follows:

java Median -37.5 -37.875 -87.9375 -41.5 100.125 53.0625 48.03125 -48

Now the expected program output is:

Median: -37.6875

Explanation: the numbers sorted into ascending order are -87.9375, -48, -41.5, -37.875, -37.5, 48.03125, 53.0625, 100.125. There are 8 number (en even number) and the two middle-most numbers are -37.875 and -37.5. The median is the mean of these two: (-37.875 + -37.5) / 2 = -37.6875.

A+ presents the exercise submission form here.

Posting submission...