Initialization of two-dimensional arrays, traversing

Source: Internet
Author: User

1  PackageCom.baidu.java;2 //initialization of 2-D arrays3  Public classArray2 {4      Public Static voidMain (string[] args) {5         //1. Static initialization6         int[] Aa=New int[][]{{3,4,5},{6,7,8,9},{1,2}};7         //2.1 Dynamic Initialization8String[][] Bb=NewSTRING[6][5];//think of it as 6 groups, 5 people per group9         //2.2 Dynamic InitializationTenString[][] Cc=NewString[6][];//define 6 groups, each with an indeterminate number of members Onecc[0]=NewSTRING[5];//First Group of 5 persons Acc[1]=NewSTRING[6];//second group of 6 persons -cc[2]=NewSTRING[2];//Third Group of 2 persons -cc[3]=NewSTRING[3];//Fourth Group of 3 persons thecc[4]=NewSTRING[6];//Fifth Group of 6 persons -cc[5]=NewSTRING[8];//Sixth Group of 8 persons -         //How to assign a value to an element in a two-dimensional array -         int[] myint=New int[3] [2]; +myint[0][0]=90;//First number of first row -myint[2][1]=100;//The last number in the third row +         //3. Length of two-D array lengths Property ASystem.out.println (myint.length);//3, Number of rows atSystem.out.println (myint[1].length);//2, the length of the second line -System.out.println (cc[5].length);//8, the last of the President -         //4. Traversal of two-dimensional arrays -System.out.println ("Iterate through all the elements in the AA array is:"); -          for(inti=0;i<aa.length;i++) {//number of rows traversing the AA array -              for(intj=0;j<aa[i].length;j++) {//traverse the number of rows per row of AA arrays inSystem.out.print (aa[i][j]+ "");//Output This element -             } toSystem.out.println ();//line Break +         } -System.out.println ("Iterates through all the elements in the Myint array is:"); the          for(inti=0;i<myint.length;i++) {//the number of rows traversing the myint array *              for(intj=0;j<myint[i].length;j++) {//iterate through the myint array per row count $System.out.print (myint[i][j]+ "");//Output This elementPanax Notoginseng             } -System.out.println ();//line Break the         } +     } A}

Operation Result:

Initialization of two-dimensional arrays, traversing

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.