Say I have a 2D array:
1.007, 0.003, 0.003
0.0095, 2.003, 0.007
1.005, 0.008, 0.001
0.003, 6.884, 0.007
How can I go through the columns such that I get an average of the numbers greater than 1? Such as: (1.007+1.005)/2 = 1.006
[1.006, 4.4435, 0]
I wrote this so far. Been working on it for days, but I can't get it to work.
double sum=0;
for(int j = 0; j <data[0].length; ++j) { // col
for( int i = 0; i < data.length; ++i) { // row
if (data[i][j]>=1){
sum=sum+data[i][j];
System.out.println(sum);
// j+=1;
}
}
}
data is my 2D array.
Thanks!