151k views
3 votes
In business applications, you are often asked to compute the mean and standard deviation of data. The mean is simply the average of the numbers. The standard deviation is a statistic that tells you how tightly all the data are clustered around the mean in a set of data. Compute the standard deviation of numbers. Please use the following formula to compute the standard deviation of n numbers. m???????????? = ∑ x???? ???? ????=1 ???? = x1+x2+⋯+x???? ???? ???????????????????????????????? ????????????????????????????o???? = √ ∑ (x???? − m????????????) ???? 2 ????=1 ???? − 1 To compute the standard deviation using the above formula, you have to store the individual numbers using an array, so they can be used after the mean is obtained. Your program should contain the following methods: /** to compute the deviation of double values**/ public static double deviation(double[] x) /** to compute the mean of an array of double values**/ public static double mean(double[] x) write a test program that prompts the user to en

User Tajma
by
5.8k points

1 Answer

3 votes

Answer:

Test program is written below.

Step-by-step explanation:

import java.util.Scanner;

public class MeanAndMedian {

public static double mean(double[] x) {

double avg = 0;

for (int i = 0; i < x.length; ++i) {

avg += x[i];

}

return avg / x.length;

}

public static double deviation(double[] x) {

double m = mean(x);

double total = 0;

for (int i = 0; i < x.length; ++i) {

total += (x[i] - m) * (x[i] - m);

}

return Math.sqrt(total / (x.length - 1));

}

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

System.out.print("Enter 10 numbers: ");

double x[] = new double[10];

for (int i = 0; i < x.length; ++i) {

x[i] = in.nextDouble();

}

System.out.printf("The mean is %.2f\\", mean(x));

System.out.printf("The standard standardDeviation is %.5f\\", deviation(x));

}

}

In business applications, you are often asked to compute the mean and standard deviation-example-1
User AriehGlazer
by
6.3k points