Welcome to Westonci.ca, the ultimate question and answer platform. Get expert answers to your questions quickly and accurately. Our platform offers a seamless experience for finding reliable answers from a network of knowledgeable professionals. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.
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 hope this information was helpful. Feel free to return anytime for more answers to your questions and concerns. We hope this was helpful. Please come back whenever you need more information or answers to your queries. Discover more at Westonci.ca. Return for the latest expert answers and updates on various topics.