-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise07_11.java
More file actions
43 lines (36 loc) · 1.21 KB
/
Copy pathExercise07_11.java
File metadata and controls
43 lines (36 loc) · 1.21 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
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author jorda
*/
public class Exercise07_11 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter ten numbers and hit enter: ");
double[] UserInputArray = new double[10];
for (int index = 0; index < UserInputArray.length; index++)
UserInputArray[index] = input.nextDouble();
System.out.println("The mean is " + mean(UserInputArray));
System.out.println("The standard deviation is " + deviation(UserInputArray));
}
public static double deviation (double[] array){
double deviation = 0;
double mean = mean(array);
for (double i: array){
deviation += Math.pow(i - mean, 2);
}
return Math.sqrt(deviation / (array.length - 1));
}
public static double mean(double[] array){
double mean = 0;
for (double i: array){
mean += i;
}
return mean / array.length;
}
}