Welcome to Westonci.ca, where your questions are met with accurate answers from a community of experts and enthusiasts. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts. Join our platform to connect with experts ready to provide precise answers to your questions in different areas.
Sagot :
Answer:
Explanation:
The following code is written in Java and creates the two methods as requested each returning the desired double[] array with the averages. Both have been tested as seen in the example below and output the correct output as per the example in the question. they simply need to be added to whatever code you want.
public static double[] rowAvg(int[][] array) {
double result[] = new double[array.length];
for (int x = 0; x < array.length; x++) {
double average = 0;
for (int y = 0; y < array[x].length; y++) {
average += array[x][y];
}
average = average / array[x].length;
result[x] = average;
}
return result;
}
public static double[] colAvg(int[][] array) {
double result[] = new double[array[0].length];
for (int x = 0; x < array[x].length; x++) {
double average = 0;
for (int y = 0; y < array.length; y++) {
average += array[y][x];
}
average = average / array.length;
result[x] = average;
}
return result;
}
We appreciate your time on our site. Don't hesitate to return whenever you have more questions or need further clarification. We appreciate your time. Please come back anytime for the latest information and answers to your questions. Find reliable answers at Westonci.ca. Visit us again for the latest updates and expert advice.