forked from sayrgyiwoody/java_ex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathex_11.java
36 lines (27 loc) · 999 Bytes
/
ex_11.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
package chapter_10;
import java.util.Scanner;
public class ex_11 {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
System.out.println("Enter value of N : ");
int N = scn.nextInt();
double[] numbers = new double[N];
double n;
double sum = 0;
for(int i = 0 ; i < N ; i++){
System.out.println("Enter number " + (i+1) + "/" + N + " : ");
n = scn.nextDouble();
numbers[i] = n;
sum += numbers[i];
}
double avg = sum/N;
double[] diffSquare = new double [N];
double totalDiffSquare = 0 ;
for(int j = 0; j < N ; j++){
diffSquare[j] = Math.pow((numbers[j]-avg), 2);
totalDiffSquare += diffSquare[j];
}
double standardDeviation = Math.sqrt(totalDiffSquare/N);
System.out.println("Standard Deviation for N = " + N +" : " + String.format("%.4f", standardDeviation));
}
}