arithmetic mean, median, mode, and standard deviation of an integer data set. The data
points are input by the user from keyboard. This program will display the output similar to
the one shown below:
If you are not sure about statistical information such as arithmetic mean, median, mode,
and standard deviation, you will need to read this page:
Descriptive Measures
Solution:
import java.util.Scanner;
int n;
float mean,median,std;
Scanner sc=new Scanner(System.in);
System.out.print("Enter number of data points:");
n=sc.nextInt();
if (n < 3)
{
System.out.println("The number of data points should be greater than 2.");
}
else
{
mean = (float)sum / n;
//calculate median
//If n is odd, median=dataset[n/2]
//If n is even, median=(dataset[n/2]+dataset[1+n/2])/2
//The index of array starts from 0, so you need to subtract 1 from the indices used in
calculating the median
if (n % 2 != 0) median = dataset[n / 2];
else median = (dataset[(n / 2) - 1] + dataset[n / 2]) / (float)2;
int max;
int k = 0;
max = mode[0][0];
for (j = 0; j < n; j++)
if (max < mode[j][0]) { max = mode[j][0]; k = j; }
//Show results
System.out.println("Statistical Information:");
System.out.println("===============================");
System.out.println("Arithmetic mean:"+mean);
System.out.println("Median:"+median);
if (mode[k][1] != 0)
System.out.println("Mode:"+ mode[k][1]);
else System.out.println("Mode: no mode");
System.out.println("Standard deviation:"+std);
//