The standard deviation of a list of numbers is a measure of

The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clustered close to the average. If the standard deviation is large, the numbers are scattered far from the average. The standard deviation of a list of numbers n1, n2, n3, and so forth is defined as the square root of the average of the following numbers: (n1 - a)^2, (n2 - a)^2, (n3 - a)^2, and so forth. The number a is the average of the numbers n1, n2, n3, and so forth. Define a static method that takes a partially filled array of numbers as its argument and returns the standard deviation of the numbers in the partially filled array. Since a partially filled array requires two arguments, the method will actually have two formal parameters, an array parameter and a formal parameter of type int that gives the number of array positions used. The numbers in the array will be of type double. Write a suitable test program for your method.

Solution

//Program

import java.util.Scanner;

public class stdDemo
{
   public static void main(String[] args)
   {
double[] array = new double[100];
       int n;
       Scanner input= new Scanner(System.in);
       System.out.println(\"Enter the size of the array: \");
       n=input.nextInt());
System.out.println(\"Enter the array elements: \");
       for(int i=0;i<n;i++)
       {
       array[i]=input.nextDouble();
       }
double std=standard_deviation(array,n);
       System.out.println(\"Standard deviation: \"+std);
   }

static double standard(double[] array, int n)
   {
       double avg = 0;
       for(int i = 0; i < n; i++)
           avg = avg + array[i];
       return avg/n;
   }
}

The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are c

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site