Created
November 9, 2013 22:00
-
-
Save caspar/7390605 to your computer and use it in GitHub Desktop.
Calculate the standard deviation of an array.
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 Arrays3{ | |
public double mean(double[] array){ | |
double sum = 0; | |
for (int i = 0; i < array.length; i ++){ | |
sum = sum + array[i]; | |
} | |
return sum; | |
} | |
public double stddev(double[] array){ | |
double[] temp = new double[array.length]; | |
double mean = mean(array); | |
for (int i = 0; i < array.length; i ++) | |
temp[i] = ((array[i] - mean) ^ 2); | |
int result = sqrt(mean(temp)); | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment