about summary refs log tree commit diff
path: root/usth/ICT2.2/labwork/4/Stats.java
blob: 88d68327cde47d5e443ace1e93070ba28ccdc776 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.ArrayList;
import java.util.Scanner;

class Stats
{
  public static void main(String... args)
  {
    var scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    var numbers = new ArrayList<Double>();
    for (int i = 0; i < n; ++i)
      numbers.add(scanner.nextDouble());

    double m = numbers.stream().mapToDouble(Double::doubleValue).sum() / n;
    double s = Math.sqrt(numbers.stream()
                         .mapToDouble(x -> Math.pow(x - m, 2)).sum() / n);
    System.out.printf("Mean: %f\nStandard deviation: %f\n", m, s);
  }
}