Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.
Become a Premium Member and unlock a new, free course in leading technologies each month.
public static double stdev(int a[]){
double mean = 0;
int sum = 0;
//1. Work out the Mean (the simple average of the numbers)
for (int i = 0; i < a.length; i++) {
sum += a[i];
if(i == a.length -1){
mean = sum/a.length;
}
}
//2. Then for each number: subtract the Mean and square the result
//GET DIFFERENCE
double variance = 0;
double [] b = new double [a.length];
for (int i = 0; i < a.length; i++) {
//b[i] = Math.sqrt(Math.abs(a[i] - mean));
double diff = Math.abs(a[i] - mean);
b[i] = diff * diff;
}
//3. Then work out the mean of those squared differences.
for (int i = 0; i < b.length; i++) {
variance += b[i]/b.length;
}
//4. Take the square root of that and you are done!
double standardDeviation = Math.sqrt(Math.ceil(variance));
return standardDeviation;
}
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
double diff = a[i] - mean;
variance += b[i]/(b.length-1);
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.