Standard deviation

Standard deviation

program to calculate the standard deviation of an array of values.the array elements are read from terminal.use function to calculate standard deviation and mean.

View Answers

December 10, 2010 at 1:39 PM

Hi Friend,

Try the following code:

import java.util.*;

public class StandardDeviation{
        public double findMean(int array[]){
        double total = 0;
        for(int i = 0; i < array.length; i++){
            total = total + array[i];
        }
        double mean = total/array.length;
        return mean;
    }
      public void findStandardDeviation(int array[]){
        double mean = findMean(array);
        System.out.println("Mean is: "+mean);
        double d1 = 0;
        double d2 = 0;
        double sum = 0;
            for(int i = 0; i < array.length; i++){
                d2 = (mean - array[i])*(mean - array[i]);
                d1 = d2 + d1;
            }
        System.out.println("Standard Deviation: " + Math.sqrt((d1/(array.length-1))));
            }

    public static void main(String args[]){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter Array Elements: ");
        int array[] = new int[5];
        for(int i=0;i<array.length;i++){
            array[i]=input.nextInt();
        }
        StandardDeviation sd = new StandardDeviation();
        sd.findStandardDeviation(array);
        }
}

Thanks









Related Tutorials/Questions & Answers:
Standard deviation
Standard deviation  program to calculate the standard deviation of an array of values.the array elements are read from terminal.use function to calculate standard deviation and mean
ModuleNotFoundError: No module named 'dbus-deviation'
ModuleNotFoundError: No module named 'dbus-deviation'  Hi, My... named 'dbus-deviation' How to remove the ModuleNotFoundError: No module named 'dbus-deviation' error? Thanks   Hi, In your python
Advertisements
ModuleNotFoundError: No module named 'dbus-deviation'
ModuleNotFoundError: No module named 'dbus-deviation'  Hi, My... named 'dbus-deviation' How to remove the ModuleNotFoundError: No module named 'dbus-deviation' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dbus-deviation'
ModuleNotFoundError: No module named 'dbus-deviation'  Hi, My... named 'dbus-deviation' How to remove the ModuleNotFoundError: No module named 'dbus-deviation' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'seasonal-behavior-deviation'
ModuleNotFoundError: No module named 'seasonal-behavior-deviation'  ...: No module named 'seasonal-behavior-deviation' How to remove the ModuleNotFoundError: No module named 'seasonal-behavior-deviation' error? Thanks
ModuleNotFoundError: No module named 'standard'
ModuleNotFoundError: No module named 'standard'  Hi, My Python... 'standard' How to remove the ModuleNotFoundError: No module named 'standard... to install padas library. You can install standard python with following
standard format in C++
standard format in C++  Please help me with this one. thank you so much. **"Write a C++ program to read a date in US standard format (mm dd yyyy) and print it in Australia standard format (dd mm yyyy
spring standard tag libraries
spring standard tag libraries  hello sir please tell me how to write the jsp in Spring frame work using spring standard tag libraries
Version of taglibs>standard dependency
List of Version of taglibs>standard dependency
standard serviceregistrybuilder example
standard serviceregistrybuilder example  can any one share me the standard serviceregistrybuilder example code? My project is in Hibernate 4.3.1.... in Hibernate 4.3.1?. It will explain you how to use the standard
Joomla Standard Package
Joomla Standard Package In this package we offer a complete standard package that can be customize or upgraded later as per the requirement of the clients. The client itself can modify and manage
standard action - JSP-Servlet
standard action  Any one please tell me what is the function of standard actions tags and the deatils of its atrributes along with example. ... or a standard tag. For Example : Action may display an output or write some value
the standard isolation levels defined by JDBC
the standard isolation levels defined by JDBC  What are the standard isolation levels defined by JDBC
Replace JSF Standard Error Message
Replace JSF Standard Error Message  How can we replace the JSF Standard Error Message
ModuleNotFoundError: No module named 'lucterios-standard'
ModuleNotFoundError: No module named 'lucterios-standard'  Hi, My... named 'lucterios-standard' How to remove the ModuleNotFoundError: No module named 'lucterios-standard' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'dicom-standard'
ModuleNotFoundError: No module named 'dicom-standard'  Hi, My... named 'dicom-standard' How to remove the ModuleNotFoundError: No module named 'dicom-standard' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'dicom-standard'
ModuleNotFoundError: No module named 'dicom-standard'  Hi, My... named 'dicom-standard' How to remove the ModuleNotFoundError: No module named 'dicom-standard' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'standard-names'
ModuleNotFoundError: No module named 'standard-names'  Hi, My... named 'standard-names' How to remove the ModuleNotFoundError: No module named 'standard-names' error? Thanks   Hi, In your python
Version of taglibs>standard-doc dependency
List of Version of taglibs>standard-doc dependency
Version of taglibs>standard-examples dependency
List of Version of taglibs>standard-examples dependency
Version of com.inkapplications>android-standard dependency
List of Version of com.inkapplications>android-standard dependency
Version of com.theoryinpractise>halbuilder-standard dependency
List of Version of com.theoryinpractise>halbuilder-standard dependency
Java 2 SDK, Standard Edition,
Java 2 SDK, Standard Edition,  Once I have the Java 2 SDK, Standard Edition, from Sun, what else do I need to connect to a database
Maven Dependency standard >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.2 in your project
Maven Dependency standard >> 1.0.5
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.5 in your project
Maven Dependency standard >> 1.1.1
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.1.1 in your project
Maven Dependency standard >> 1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0 in your project
Maven Dependency standard >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.1 in your project
Maven Dependency standard >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.3 in your project
Maven Dependency standard >> 1.0.4
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.4 in your project
Maven Dependency standard >> 1.0.6
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.0.6 in your project
Maven Dependency standard >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.1.0 in your project
Maven Dependency standard >> 1.1.2
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard version1.1.2 in your project
java standard edition - Java Beginners
java standard edition  good evening sir. i want to install j2se version-6 on my laptop and netbeans, so i want to know the path: and classpath: to type in the environmental variables Dialogue box. also full details about
ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin'
ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin...: ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-product-standard
ModuleNotFoundError: No module named 'odoo8-addon-product-standard-margin'
ModuleNotFoundError: No module named 'odoo8-addon-product-standard-margin' ...: ModuleNotFoundError: No module named 'odoo8-addon-product-standard-margin' How to remove the ModuleNotFoundError: No module named 'odoo8-addon-product-standard
ModuleNotFoundError: No module named 'UW-Grading-Standard-LTI'
ModuleNotFoundError: No module named 'UW-Grading-Standard-LTI'  Hi...: No module named 'UW-Grading-Standard-LTI' How to remove the ModuleNotFoundError: No module named 'UW-Grading-Standard-LTI' error? Thanks   
ModuleNotFoundError: No module named 'cloudshell-shell-firewall-standard'
ModuleNotFoundError: No module named 'cloudshell-shell-firewall-standard' ...: ModuleNotFoundError: No module named 'cloudshell-shell-firewall-standard' How to remove the ModuleNotFoundError: No module named 'cloudshell-shell-firewall-standard
ModuleNotFoundError: No module named 'cloudshell-shell-networking-standard'
ModuleNotFoundError: No module named 'cloudshell-shell-networking-standard...: ModuleNotFoundError: No module named 'cloudshell-shell-networking-standard' How...-standard' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'django-standard-form'
ModuleNotFoundError: No module named 'django-standard-form'  Hi...: No module named 'django-standard-form' How to remove the ModuleNotFoundError: No module named 'django-standard-form' error? Thanks   Hi
ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin'
ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin...: ModuleNotFoundError: No module named 'odoo10-addon-product-standard-margin' How to remove the ModuleNotFoundError: No module named 'odoo10-addon-product-standard
Version of geronimo>geronimo-console-standard dependency
List of Version of geronimo>geronimo-console-standard dependency
Version of org.basepom>basepom-standard-oss dependency
List of Version of org.basepom>basepom-standard-oss dependency
Maven Dependency standard-doc >> 1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0 in your project
Maven Dependency standard-doc >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0.1 in your project
Maven Dependency standard-doc >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0.3 in your project
Maven Dependency standard-doc >> 1.0.4
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0.4 in your project
Maven Dependency standard-doc >> 1.0.5
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0.5 in your project
Maven Dependency standard-doc >> 1.0.6
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.0.6 in your project
Maven Dependency standard-doc >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of taglibs >> standard-doc version1.1.0 in your project

Ads