
Java Program To Calculate Mean Median Mode
Well before starting, let’s look at the basic defention and how we find mean, median and mode. Both these are 3 variables to find the average value or an approximate value of a list, but yet they have different values as they are based on 3 different concepts
Write a Java program to answer about the statistical information such as arithmetic mean, median, mode, and standard deviation of an integer data set. The data points are input by the user from keyboard. Java Program to compute standard deviation,variance of population & sample with example. VK November 8, 2014 core java, program In continuation to my earlier Java code to find all permutations of a String using recursion, let us write another useful java program to compute Variance and Standard Deviation.
Concepts of mean, median and mode
What is mean ?
Mean is same as average. The mean is found by adding up all of the given data and dividing by the number of elements.
Example: Mean of 1,2,3,4,5 is
(1+2+3+4+5 )/5 = 15/3 = 3
What is Median ?
The median is the middle number in an ordered list (ascending or descending). First you arrange the numbers in orders in ascending order, then you find the middle number and save it as median
Example:
1 2 3 4 5
Median is 3
What is Mode ?
Mode is the element which happens most number of time in the list. If no element happens more than once, all elements are considered as mode.
Algorithm
- Start
- Declare an array a[20], sum =0,i=0,j=0,z=0
- Read number of terms n
- Repeat step 5 & 6 while (i<n)
- sum=sum+a[i]
- next i
- mean=sum/n
- if (n%2=0)
median=(a[n/2] +a[n/2-1])/2
else
median=a[n/2] - print mean and median
- repeat step 11 & 12 when i=0 to n, j=0 to i
- if a[i]=a[j], then b[i]++
- if b[i]>z, then z=b[i]
- For i=0 to n if b[i]=z, print b[i]
- end
Program
This is the C program to find the mean,median,mode and range of an array
Mean, median, and mode are three kinds of “averages”. There are many “averages” in statistics, but these are, I think, the three most common, and are certainly the three you are most likely to encounter in your pre-statistics courses, if the topic comes up at all.
The “mean” is the “average” you’re used to, where you add up all the numbers and then divide by the number of numbers. The “median” is the “middle” value in the list of numbers. To find the median, your numbers have to be listed in numerical order, so you may have to rewrite your list first. The “mode” is the value that occurs most often. If no number is repeated, then there is no mode for the list.
The “range” is just the difference between the largest and smallest values.
By 2008, the complete English version, Encarta Premium, consisted of more than 62,000 articles, numerous photos and illustrations, music clips, videos, interactive content, timelines, maps, atlases and homework tools. Microsoft Encarta was a digital multimedia encyclopedia published by Microsoft Corporation from 1993 to 2009. Originally sold on CD-ROM or DVD, it was also later available on the World Wide Web via an annual subscription – although later many articles could also be viewed free online with advertisements.
Find the mean, median, mode, and range for the following list of values:
13, 18, 13, 14, 13, 16, 14, 21, 13
The mean is the usual average, so:
(13 + 18 + 13 + 14 + 13 + 16 + 14 + 21 + 13) ÷ 9 = 15

Note that the mean isn’t a value from the original list. This is a common result. You should not assume that your mean will be one of your original numbers.
The median is the middle value, so I’ll have to rewrite the list in order:
13, 13, 13, 13, 14, 14, 16, 18, 21
There are nine numbers in the list, so the middle one will be the (9 + 1) ÷ 2 = 10 ÷ 2 = 5th number:
13, 13, 13, 13, 14, 14, 16, 18, 21
So the median is 14.
The mode is the number that is repeated more often than any other, so 13 is the mode.
The largest value in the list is 21, and the smallest is 13, so the range is 21 – 13 = 8.
mean: 15
median: 14
mode: 13
range: 8
Note: The formula for the place to find the median is “( [the number of data points] + 1) ÷ 2”, but you don’t have to use this formula. You can just count in from both ends of the list until you meet in the middle, if you prefer. Either way will work.