Question: Write a method named average2D that computes the average of all the double values found within a given 2-dimensional array. You should use a nested
Write a method named average2D that computes the average of all the double values found within a given 2-dimensional array. You should use a nested loop. In the inner loop, update the sum and the count. The method should return the average as calculated by sum/count.
I've provided a template to help you get started (see link below). Create a new project named Test3S2, and cut and paste the appropriate code into your project.
package test3.s2;
import java.util.Arrays;
/** * * @Wuchen Peng insert your name here */ public class Test3S2 {
/** * @param args the command line arguments */ public static void main(String[] args) { double[][] testArray = {{1.0, 2.0, 3.0}, {4.0, 5.0, 6.0}};
double avg = average2D(testArray);
System.out.printf("The average of the values found in the array is -> %.2f ", avg); } public static double average2D(double[][] array){ int count = 0; double sum = 0; // // Write your Test 3 code here //
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
