Java double type calculate standard deviation

Description

Java double type calculate standard deviation

import java.util.Scanner;

public class Main {

    public static void main(String[] strings) {

        double total = 0.0;
        double squareTotal = 0.0;

        Scanner input = new Scanner(System.in);
        System.out.print("Enter a number: ");

        for (int i = 0; i < 10; i++) {
            double number = input.nextDouble();
            total += number;/*from  w  w  w  . ja va2 s. c o m*/
            squareTotal += Math.pow(number, 2.0);
        }
        double deviation = Math.pow((squareTotal - total * total / 10.0) / 9.0, 0.5);

        System.out.println("The standard deviation is " + deviation);
    }
}



PreviousNext

Related