Java Program To Calculate Standard Deviation
Chapter:
Math Class
Last Updated:
21-09-2017 17:08:47 UTC
Program:
/* ............... START ............... */
public class JavaStandardDeviation {
public static void main(String[] args) {
double[] numArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double SD = calculateSD(numArray);
System.out.format("Standard Deviation = %.6f", SD);
}
public static double calculateSD(double numArray[]) {
double sum = 0.0, standardDeviation = 0.0;
for (double num : numArray) {
sum += num;
}
double mean = sum / 10;
for (double num : numArray) {
standardDeviation += Math.pow(num - mean, 2);
}
return Math.sqrt(standardDeviation / 10);
}
}
/* ............... END ............... */
Output
Standard Deviation = 2.872281
Notes:
-
In statistics, the standard deviation (SD, also represented by the Greek letter sigma σ or the Latin letter s) is a measure that is used to quantify the amount of variation or dispersion of a set of data values.
- In the above program, we've used the help of Math.pow() and Math.sqrt() to calculate the power and square root respectively.
Tags
Calculate Standard Deviation, Java, Math