Standard Deviation Program in Java

Java program to calculate standard deviation. A standard deviation is a statistic that measures a dataset’s dispersion from its mean. By calculating each data point’s divergence from the mean, the standard deviation is calculated as the square root of variance.

public class Main
{
public static void main(String[] args)
{
double[] numArray = { 1, 4,5,6,7,5,8,9, 10 };
double SD = calculateSD(numArray);
System.out.format("SD value is = %.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:

SD value is = 2.601044

What is standard deviation in java program

A data set’s standard deviation is a measure of how spread out it is. It can be found in a wide range of applications. Standard deviations of price data are commonly used as a measure of volatility in finance. Standard deviations are an important aspect of estimating margins of error in opinion polling.

A standard deviation is a statistic that measures a dataset’s dispersion from its mean. There is a bigger variance within the data set if the data points are further from the mean; consequently, the more spread out the data, the higher the standard deviation.

What is double data type in java program

A primitive data type in Java is the double keyword. It’s a 64-bit IEEE 754 floating point with double precision. It’s where variables and methods are declared. It is used to represent decimal numbers in general.

Double is more exact than float and can store 64 bits, which is twice as much as float. We favour double over float for storing huge numbers because it is more exact.

What is math.pow in java

The Math. pow() function converts the base to the exponent power, where the base and exponent are both in the decimal system. java.lang is a programming language that was developed by Sun Microsystems.

A number is raised to the power of another integer using the math. pow() function. This function takes two arguments and returns the first parameter’s value multiplied by the second. The value of the first parameter raised to the power of the second argument is returned by pow(). The pow() method returns a double value.

Similar Programs