Write a Java Program to Calculate Standard Deviation

Java Program to Calculate Standard Deviation

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn Java programming concepts. You can learn Java  language at your own speed and time. One can learn concepts of Java language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Java Program to Calculate Standard Deviation
Java Program to Calculate Standard Deviation

Write a Java Program to Calculate Standard Deviation

PROGRAM: Java Program to Calculate Standard Deviation

/*Java Program to Calculate Standard Deviation*/

public class StandardDeviation {

public static void main(String[] args) {
double[] numArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
double SD = calculateSD(numArray);

System.out.format(“Standard Deviation = %.6f”, SD);
}

public static double calculateSD(double numArray[])
{
double sum = 0.0, standardDeviation = 0.0;
int length = numArray.length;

for(double num : numArray) {
sum += num;
}

double mean = sum/length;

for(double num: numArray) {
standardDeviation += Math.pow(num – mean, 2);
}

return Math.sqrt(standardDeviation/length);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *