Skip to content

Instantly share code, notes, and snippets.

@caspar
Created November 9, 2013 22:00
Show Gist options
  • Save caspar/7390605 to your computer and use it in GitHub Desktop.
Save caspar/7390605 to your computer and use it in GitHub Desktop.
Calculate the standard deviation of an array.
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