Skip to content

Commit dfb4365

Browse files
authored
Standard Deviation
Java Program to create a Standard Deviation
1 parent 7f1df0c commit dfb4365

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Standard Deviation

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public class StandardDeviation {
2+
3+
public static void main(String[] args) {
4+
double[] numArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
5+
double SD = calculateSD(numArray);
6+
7+
System.out.format("Standard Deviation = %.6f", SD);
8+
}
9+
10+
public static double calculateSD(double numArray[])
11+
{
12+
double sum = 0.0, standardDeviation = 0.0;
13+
int length = numArray.length;
14+
15+
for(double num : numArray) {
16+
sum += num;
17+
}
18+
19+
double mean = sum/length;
20+
21+
for(double num: numArray) {
22+
standardDeviation += Math.pow(num - mean, 2);
23+
}
24+
25+
return Math.sqrt(standardDeviation/length);
26+
}
27+
}

0 commit comments

Comments
 (0)