Add Standard Deviation (#3039)

This commit is contained in:
RaghavTaneja
2022-05-01 02:32:03 -05:00
committed by GitHub
parent 1a230bd61e
commit c52b2a649c
2 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package com.thealgorithms.maths;
public class StandardDeviation {
public static double stdDev(double[] data)
{
double var = 0;
double avg = 0;
for (int i = 0; i < data.length; i++)
{
avg += data[i];
}
avg /= data.length;
for (int j = 0; j < data.length; j++)
{
var += Math.pow((data[j] - avg), 2);
}
var /= data.length;
return Math.sqrt(var);
}
}