forked from sayrgyiwoody/java_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_12.java
47 lines (34 loc) · 1.12 KB
/
ex_12.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
40
41
42
43
44
45
46
47
package chapter_10;
import java.util.List;
import java.util.Scanner;
import java.util.ArrayList;
public class ex_12 {
public static void main(String[] args) {
List<Double> numbers = new ArrayList<Double>();
int N ;
Scanner scn = new Scanner(System.in);
System.out.println("Enter value of N : ");
N = scn.nextInt();
double n , sum = 0, avg;
for(int i= 0 ; i < N ; i++){
System.out.println("Enter number " + (i+1) + "/" + N + " : ");
n = scn.nextDouble();
numbers.add(n);
sum += n;
}
// for (Double s : numbers) {
// sum += s;
// }
avg = sum/N;
List<Double> diffSquare = new ArrayList<Double>();
for(double s : numbers){
diffSquare.add(Math.pow((s-avg), 2));
}
double totalDiffSquare = 0;
for(double d : diffSquare){
totalDiffSquare += d;
}
double standardDeviation = Math.sqrt(totalDiffSquare/N);
System.out.println("Standard Deviation : " + String.format("%.4f", standardDeviation));
}
}