I need help with the following program:
"Write a method that will take a two-dimensional array of doubles as an input parameter & return the average of the elements of the array."
Can anyone tell me how to go about it?
My current code:
public static double average(float arr[][]) {
double sum = 0;
int count = 0;
for (int row = 0; row < arr.length; row++)
for (int col = 0; col < arr[0].length; col++)
{
sum += arr[row][col];
count++;
}
return sum/count;
}
I don't know how to let the user input the array elements and array dimensions (row/columns). Also how do I call this method from main? I am getting errors.