1 PackageCom.shuzu;2 3 Public classAverage {4 Public Static voidMain (string[] args) {5 int[] A = {{2,3},{6,7},{8,20,20}};6Average Ave =NewAverage ();7 Ave.stravg (a);8System.out.println ("");9 Ave.sumavg (a);Ten } One A //find the average of all the values - Public voidSumavg (int[] b) { - intsum = 0; the intN=0; - floatAve=0; - for(introw=0;row<b.length;row++){ - for(intcol=0;col<b[row].length;col++){ +sum=sum+B[row][col]; -n++; + } A } atAve = sum/N; -System.out.println ("Number of values in the array:" +n+ "all the array values are added together:" +sum+ "gets the average:" +Ave); - } - //find the average of each array in a two-dimensional array - Public voidStravg (int[] b) { - floatAve =0; in intsum = 0; - for(introw=0;row<b.length;row++){ to for(intcol=0;col<b[row].length;col++){ +sum = sum+B[row][col]; -Ave = sum/b[row].length; the } *System.out.println ("The and of each array in a two-dimensional array: the" +sum+ "mean is:" +Ave); $Ave=0;Panax NotoginsengSum=0; - } the } +}
Averaging of two-dimensional arrays