-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathestatisticas.java
More file actions
60 lines (41 loc) · 1.44 KB
/
estatisticas.java
File metadata and controls
60 lines (41 loc) · 1.44 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
49
50
51
52
53
54
55
56
57
58
59
60
import java.util.ArrayList;
import java.util.List;
public class estatisticas {
static double Soma(Double vetor[]) {
int tamanhoVetor = vetor.length;
double soma = 0;
for (int i = 0; i < tamanhoVetor; i++)
soma += vetor[i];
return soma;
}
static double Media(Double vetor[]) {
int tamanhoVetor = vetor.length;
return Soma(vetor) / (double) tamanhoVetor;
}
static double Variancia(Double vetor[]) {
int tamanhoVetor = vetor.length;
double media = Media(vetor);
double QuadradoDiferenca = 0;
for (int i = 0; i < tamanhoVetor; i++)
QuadradoDiferenca += Math.pow(vetor[i] - media, 2);
return QuadradoDiferenca / tamanhoVetor;
}
static double DesvioPadrao(Double vetor[]) {
return Math.sqrt(Variancia(vetor));
}
public static void main (String[] args) {
List<Double> numeros = new ArrayList<>();
for (int i = 0; i < args.length; i++)
numeros.add(Double.parseDouble(args[i]));
Double[] vetor = numeros.toArray(new Double[0]);
System.out.print("Números: ");
for (int i = 0; i < vetor.length; i++)
System.out.print(vetor[i] + " ");
System.out.println();
System.out.println("Qtde de Número: " + vetor.length);
System.out.println("Soma: " + Soma(vetor));
System.out.println("Média: " + Media(vetor));
System.out.println("Variância: " + Variancia(vetor));
System.out.println("Desvio Padrão: " + DesvioPadrao(vetor));
}
}