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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started