Mean and standard deviation. Write a program that reads a set of floating - poin
ID: 3650901 • Letter: M
Question
Mean and standard deviation. Write a program that reads a set of floating - point data values .choose an appropriate mechanism for prompting for the end of the data set. When all values have been read, print out the count of the values , the average , and the standard deviation .the average of a data set { x1 ,..,x n} is x = x i/n, where x I =x1 + .+x 12 is the sum of the input values. The stander deviation is However , this formula is not suitable for the task. By the time the program has computed x, the individual xi are long gone .until you know how to save these values ,use the numerically less stable formula S= You can compute this quantity by keeping track of the count ,the sum ,and the sum of squares as you process the input values.Explanation / Answer
Please rate...
Program StandardDeviation.java
==================================================
import java.util.Scanner;
class StandardDeviation
{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int i=0;
double sum=0,sums=0;
System.out.println("Enter the numbers[enter -1 to indicate end of data set]");
while(true)
{
System.out.print("Enter #"+(i+1)+": ");
double a=s.nextDouble();
if(a==-1)break;
i++;
sum=sum+a;
sums=sums+(a*a);
}
System.out.println("The total number of numbers are: "+i);
System.out.println("The average of the numbers is: "+(sum/i));
double sd=Math.sqrt((sums-((sum*sum)/i))/(i-1));
System.out.println("The standard deviation is: "+sd);
}
}
================================================
Sample output: