Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

calculate Standard Deviation in java

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);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to call child class method from parent class in java 
Java :: log4j2.properties file need to save in spring boot application 
Java :: can you use java in unity 
Java :: import class from package java 
Java :: java coding standards for classes 
Java :: biginteger modulo in java 
Java :: configuration spring boot dependency for freemarker configuration 
Java :: postfix operator in java 
Java :: style jbuttons 
Java :: my animal list 
Java :: code wars jaden casting java 
Java :: selenium firefox to foreground -python java 
Sql :: safe update mysql 
Sql :: delete mysql ubuntu 20.04 
Sql :: sql server 2016 reseed identity 
Sql :: oracle sql drop sequence 
Sql :: check timezone of mysql database 
Sql :: check database name oracle 
Sql :: finding duplicate column values in table with sql 
Sql :: this month mysql where 
Sql :: sql server alter table column nullable 
Sql :: mysql add boolean column 
Sql :: sql delete multiple ids 
Sql :: sql server connection string in .net core with password 
Sql :: postgres set sequence value to max id 
Sql :: mysql get time from datetime 
Sql :: create schema sql server 
Sql :: cast to date bigquery 
Sql :: oracle compile whole schema 
Sql :: list all permissions on a table in postgres 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =