第七章第十一题(统计:计算标准差)(Statistics: calculating standard deviation)
-
*7.11(统计:计算标准差)编程练习题5.45计算数字的标准差。本题使用一个和他不同但是等价的公式来计算n个数的标准差。
要用这个公式计算标准差,必须使用一个数组存储每个数,这样可以在获取平均值后使用他们。程序应该包含下面的方法:
public static double devition(double[] x)
public static double mean(double[] x)
编写测试程序,提示用户输入10个数,然后显示平均值和标准差,如下面的运行示例所示:
Enter 10 numbers: 1.9 2.5 3.7 2 1 6 3 4 5 2
The mean is 3.1100000000000003
The standard devition is 1.5573838462127583
*7.11(Statistics: calculating standard deviation)Program exercise 5.45 calculate the standard deviation of the number. This problem uses a different but equivalent formula to calculate the standard deviation of N numbers.
To use this formula to calculate the standard deviation, you must use an array to store each number so that you can use them after you get the average. The program should include the following methods:
public static double devition(double[] x)
public static double mean(double[] x)
Write a test program, prompt the user to enter 10 numbers, and then display the average value and standard deviation, as shown in the following running example:
Enter 10 numbers: 1.9 2.5 3.7 2 1 6 3 4 5 2
The mean is 3.1100000000000003
The standard devition is 1.5573838462127583 -
参考代码:
package chapter07; import java.util