Last active
November 6, 2016 18:45
-
-
Save brunorozendo/e3bd3cb0cbdfbfd365cf6d659e6fc0fe to your computer and use it in GitHub Desktop.
calculo da média e desvio padra
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MediaAritmeticaEDesvioPadrao{ | |
public static void main(String[] args) { | |
int tamanhoVetor = 10; | |
double soma = 0; | |
double soma2 = 0d; | |
double media = 0d; | |
double desvioPadrao = 0d; | |
for (int i = 1; i <= tamanhoVetor ; i++) { | |
soma = soma + i; | |
soma2 = soma2 + elevarAoQuadrado(i); | |
System.out.println("I = "+i); | |
} | |
media = soma/tamanhoVetor; | |
desvioPadrao = tirarRaizQuadrada( | |
(soma2-elevarAoQuadrado(soma)/tamanhoVetor) | |
/tamanhoVetor-1 | |
); | |
System.out.println("Média = "+media); | |
System.out.println("Desvio Padrão = "+desvioPadrao); | |
} | |
private static double elevarAoQuadrado(double valor){ | |
return Math.pow(valor,2); | |
} | |
private static double tirarRaizQuadrada(double valor){ | |
return Math.sqrt(valor); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment