-
Notifications
You must be signed in to change notification settings - Fork 6
/
Solution.java
39 lines (34 loc) · 1014 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
37
38
39
/*
* DeveloperName(): Jignesh Chudasama
* GithubName(): https://github.com/Jignesh-81726
*/
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);
}
}