-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstandard_deviation.java
More file actions
48 lines (41 loc) · 1.03 KB
/
standard_deviation.java
File metadata and controls
48 lines (41 loc) · 1.03 KB
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
40
41
42
43
44
45
46
47
48
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int a[]=new int[n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
Solution s=new Solution();
float mean = s.find_mean(a);
double sd=s.find_sd(a, mean;);
System.out.println(sd);
}
float find_mean(int a[])
{
int sum=0;
for(i:a)
{
sum=sum+i;
}
float mean=sum/a.length+1
return mean;
}
double find_sd(int a[], float mean)
{
double sum=0.00;
for(i:a)
{
sum=sum+[(i-mean)*(i-mean)];
}
double sd=Math.sqrt(sum);
return sd;
}
}