-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Solution.java
36 lines (31 loc) · 932 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// github.com/RodneyShag
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
/* Save input */
Scanner scan = new Scanner(System.in);
int size = scan.nextInt();
int [] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = scan.nextInt();
}
scan.close();
System.out.format("%.1f", standardDeviation(array));
}
public static double getMean(int [] array) {
int sum = 0;
for (int x : array) {
sum += x;
}
return (double) sum / array.length;
}
public static double standardDeviation(int [] array) {
double mean = getMean(array);
double sum = 0;
for (int x : array) {
sum += Math.pow(x - mean, 2);
}
double variance = sum / array.length;
return Math.sqrt(variance);
}
}