I have 2 dimensional array, I need too calculate mean and standard deviation per row and store it in the proper place. I have write the code but it still give me the wrong result, not giving the correct answer of the intended value. could anyone help me, perhaps my code is just wrong but i dont know how to correct it. Here s the array
And here s the code itself:
public void analyze(String[][] arr) {
double res = 0.0;
double avg = 0;
double variance = 0;
double SD;
double Q = 0;
int index = 0;
for (int i = 1; i < (arr.length); i++) {
for (int j = 1; j < (arr[i].length); j++) {
res = res + Integer.parseInt(arr[i][j]);
}
avg = res / (arr[i].length - 1);
System.out.print("arr[i].length: " + arr[i].length + " ");
System.out.println("Average is " + avg);
/*
double v = Q + (arr.length - avg) * (arr.length - avg);
variance = Q / (arr.length - 1);
SD = Math.sqrt(variance);
System.out.println("average is " + avg);
System.out.println("SD");
double nums[] = { 1.0, 2.3, 3.4, 4.5, 40.5 };
double result = 0.0;
for (i = 0; i < nums.length; i++) {
result = result + nums[i];
}
System.out.println("Average is =" + result / nums.length);
*/
}
}