【发布时间】:2017-03-19 10:49:31
【问题描述】:
我有一个文件,其中包含需要存储在数组中的数字列表。如何计算数组的总体标准差? Main 类不需要更改。
主要
import java.io.BufferedReader;
import java.io.FileReader;
public class Main {
private static int NUMBERS=20;
public static void main(String[] args) {
double[] myNumbers = new double[NUMBERS];
Calculations calculations = new Calculations();
try {
calculations.readFile("numbers.txt", myNumbers);
double stdDev = calculations.computeStandardDeviation(myNumbers);
System.out.println("Population Std Dev = " + stdDev);
} catch (Exception e) {
e.printStackTrace();
}
}
}
计算
import java.io.BufferedReader;
import java.io.FileReader;
public class Calculations {
// Read integers from text file, use myArray.length as the number to read
// Read numbers as text and convert to doubles.
public void readFile(String fileName, double[] myArray) throws Exception {
FileReader fr = null;
BufferedReader br;
}
public double computeStandardDeviation(double[] myArray) {
double result = 0;
return result;
}
}
列表
9 2 5 4 12 7 8 11 9 3 7 4 12 5 4 10 9 6 9 4
【问题讨论】:
标签: arrays double text-files bufferedreader standard-deviation