For my Beginner Java Class Please and thank you Mean and standard deviation. Wri
ID: 3771089 • Letter: F
Question
For my Beginner Java Class
Please and thank you
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 {x_1, ..., x_n} is = Sigma x_i/n, where Sigma X_i = x_1 + ... + x_n is the sum of the input values. The standard deviation is s = Root Element Sigma (x_i - )^2/n -1 However, this formula is not suitable for the task. By the time the program has computed , the individual x_i are long gone. Until you know how to save these values, use the numerically less stable formulaExplanation / Answer
Procedure:
Step 1. Work out the mean
Step 2. Then for each number: subtract the Mean and square the result
Step 3. Then work out the mean of those squared differences.
Step 4. Take the square root of that.
importjava.util.*;
class Mean_SD
{
public static void main (String [] args)
{
System.out.println("Enter numbers to find standard deviation");
Scanner in = new Scanner (System.in);
double[] arr= new double [n];
double sum=0.0, mean=0.0, n;
for (inti=0; i<n; i++) //Take input in the array
{
System.out.print("Enter a number : ");
arr[i]=in.nextDouble();
sum+=arr[i]; //sum of all elements
}
mean=sum/n;
sum=0;
System.out.println("Mean : "+mean); //Display mean of all elements
double [] temp= new double[10];
for (inti=0; i<n; i++) //calculate standard deviation
{
temp[i]=Math.pow((arr[i]-mean),2);
sum+=temp[i];
}
mean=sum/10;
double deviation=Math.sqrt(mean);
System.out.println("Deviation : "+ deviation);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.