Java Learning (vi)

Source: Internet
Author: User

 Public classmatrixaddition{ Public Static voidMain (String args[]) {inti,j,k; intA[][] =New int[3] [4]; intB[][] = {{1,5,2,8},{5,9,10,-3},{2,7,-5,-18}}; intC[][] =New int[3] [4];  for(i = 0;i < 3;i++)             for(j = 0;j < 4;j++) A[i][j]= (i + 1) * (j + 2);  for(i = 0;i < a.length;i++)             for(j = 0;j < a[i].length;j++) C[i][j]=a[i][j]+B[i][j]; System.out.println ("*******matrix c********");  for(i = 0;i < c.length;i++){             for(j = 0;j < c[i].length;j++) System.out.print (C[i][j]+" "); System.out.print ("\ n"); }    }}

• Various uses of arrays

 Public classarraydemo{Static floatAveragearray (floata[]) {        floatAverage = 0; inti;  for(I =0;i < a.length;i++) {Average= Average +A[i]; }        returnaverage/a.length; }     Public Static voidMain (string[] args) {floatAverage,a[] = {1,2,3,4,5}; Average=Averagearray (a); System.out.println ("Average =" +average); }}

• Array as the parameter of the method.

• In the formal parameter list, the parentheses after the array name cannot be omitted, and the number of elements in the list cannot be given;

• When an array masterpiece is an argument, the address is passed, that is, the argument and the parameter have the same storage unit.

Java Learning (vi)

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.