我基本上是在尝试使用一个数组,它是从文件中读取的数据,然后使用该数组计算数据的平均值和标准偏差。
我似乎无法得到正确的号码。
static public double[][] calcStats(String[][] x) throws IOException {
double[][] array = new double[7][2];
double total = 0, std_dev = 0, amount = 0;
int row2 = 0;
for (int row = 1; row < x.length; row++) {
array[row2][0] = (total);
array[row2][1] = Math.sqrt(amount);
amount = 0;
total = 0;
if (row >= 2) {
row2++;
}
for (int col = 1; col < x[row].length; col++) {
total += Integer.parseInt(x[row][col]);
if (col == 4) {
total = (total / 4);
}
}
for (int col = 1; col < x[row].length; col++) {
std_dev = (Integer.parseInt(x[row][col])) - (total);
std_dev = Math.pow(std_dev, 2);
amount = +std_dev;
std_dev = 0;
if (col == 4) {
amount = (amount / 27);
}
}
}
array[row2][0] = (total);
return array;
}