• 0
Sign in to follow this  

Standard Deviation Calculator - Java


So I was bored today and thought to myself 'do you know what I don't enjoy doing? Standard Deviation, so I'm going to make something that does it for me!'. So I did :P Plus it gave me a chance to practice some Java which I seem to be doing a good job of half learning basics, forgetting then coming back to so hopefully I stick at it this time xD Anyway here is the code, do with it what you will - think of it whenever you have to do Standard Deviation, trust me it will save much boredom xD


import java.util.Scanner;

class main {

    public static void main(String [] args){

        //Known fields for equation
        double sigX = 0;
        double sigXSq = 0;
        double n;

        //Creates object to scan for user input via keyboard
        Scanner keyBoard = new Scanner(System.in);

        //So that it knows the size needed for the array
        System.out.println("Please enter the number of data there are in the data set:");
        n = keyBoard.nextDouble();
        int number = (int)n;

         //Creates double X array to store data for standard deviation
        double X[];
        X = new double[number];

        //User input of data values
        for(int i=0 ; i < number; i++){
            System.out.println("Please enter number " + (i+1));
            X[i] = keyBoard.nextDouble();
        //to find Sigma X
        for(int i=0; i < number; i++){
            sigX = sigX + X[i];
        //to find Sigma X Squared
        for(int i=0; i < number; i++){
             sigXSq = sigXSq + (Math.pow(X[i], 2));

        //Final Working
        double SDPart1 = sigXSq/n;
        double SDPart2 = Math.pow((sigX/n),2);
        double SD = Math.sqrt((SDPart1-SDPart2));

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


Share this post

Link to post
Share on other sites

2 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this