The averaging method of two-dimensional array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.