Mu class net-java first season-6-9

Source: Internet
Author: User

Source: http://www.imooc.com/code/1571

The so-called two-dimensional array, which can be simply understood as a "special" one-dimensional array, each of its array space holds a one-dimensional array.

So how to use a two-dimensional array, the steps are as follows:

1. Declaring arrays and allocating space

Or

Such as:

2. Assign Value

The assignment of a two-dimensional array, similar to a one-dimensional array, can be assigned individually by subscript, noting that the index starts at 0

You can also assign a value to an array while declaring it

Such as:

3. Working with arrays

A two-dimensional array accesses and outputs the same array of dimensions, just one more subscript. In the loop output, you need to embed a loop inside, even if you are using a double loop to output each element in a two-dimensional array. such as:

Operation Result:

What you need to know: When you define a two-dimensional array, you can specify only the number of rows, and then specify the number of columns for each row, respectively. If the number of columns per row is different, an irregular two-dimensional array is created, as follows:

The result of the operation is:

Task

Completion time to fill in the blanks!!!

Functional requirements: Define a two-dimensional array of three columns names and assign values, using a binary loop to output the elements in a two-dimensional array.

Operation Result:

Please add the Code Editor 5, 8, and line codes to complete

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3         4         //define two-dimensional arrays of three columns and assign values5names={{"Tom", "Jack", "Mike"},{"Zhangsan", "Lisi", "Wangwu"}};6                  7         //outputs the values of elements in a two-dimensional array through a double loop8          for(inti = 0; I <; i++) {9             Ten              for(intj = 0; J < Names[i].length; J + +) { One                  A System.out.println (); -             } -              the System.out.println (); -         } -     } -}

Myans:

1  Public classHelloWorld {2      Public Static voidMain (string[] args) {3         4         //define two-dimensional arrays of three columns and assign values5String[][] names={{"Tom", "Jack", "Mike"},{"Zhangsan", "Lisi", "Wangwu"}};6                  7         //outputs the values of elements in a two-dimensional array through a double loop8          for(inti = 0; i < names.length; i++) {9             Ten              for(intj = 0; J < Names[i].length; J + +) { One                  A System.out.println (Names[i][j]); -             } -              the System.out.println (); -         } -     } -}

Mu class net-java first season-6-9

Related Article

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.