Question: Java code b. find the mean and median of 20 numbers. To find a median you need to sort the 20 numbers first. You can

Java code

b. find the mean and median of 20 numbers. To find a median you need to sort the 20 numbers first.

You can use any of the sort codes posted in 'Array with Sort' post to sort the 20 numbers in your Array.

Next is to write a code to find the median of the sorted 20 numbers. Remember, your median is the

two central numbers of the 20 sorted numbers.

Below is the hint pseudocode:

if(size % 2 == 0) //if the size of the list is even; median would be the average of the two middle numbers

median = (nums[(size / 2)] + nums[size / 2 - 1]) / 2.0; //locate the subscripts of the 2 middle numbers; addition of their values/2

else

median = nums[size / 2] / 1.0; // if the size of the list is odd; median would be 1 middle number

if(size != 0)

mean = total * 1.0 / size;

System.out.println("The mean is " + mean + " and the median is " + median);

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!