Java Program to Calculate Standard Deviation

In this Java program, you’ll learn how to Calculate Standard Deviation using the Java programming language. 

How to Calculate Standard Deviation using JAVA? 

Example 1: 

RUN CODE SNIPPET
public class Main 
 { 
    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); 
    } 
}

OUTPUT 

Standard Deviation = 2.872281

Share:

Leave A Reply

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

You May Also Like

In this Java program, we will learn how to find the GCD of two numbers using Java.  GCD (Greatest Common...
  • Java
  • December 3, 2024
In this Java Program, you’ll learn how to swap two numbers using the Java programming language.  How to Swap Two...
  • Java
  • December 2, 2024
In this Java program , we will learn how to Find Largest Element in an Array in your Java program.   How to Find Largest Element...
  • Java
  • December 2, 2024