Java one-dimensional arrays, two-dimensional arrays, three-dimensional arrays, multidimensional arrays, and so on.

Source: Internet
Author: User

This array can be regarded as novice learning, from one-dimensional array to multidimensional array loop progressive, in fact, it is very simple to look at, it is known that one-dimensional, two-dimensional may often use, to use more than two-dimensional should be less.

 Public classTest { Public Static voidMain (string[] args) {/*one-dimensional arrays*/        intNum[] = {0,1,2}; /*output 3 rows of data below, 0 ~ 2*/         for(inti =0; i < num.length; i++) {System. out. println ("one-dimensional array output values:"+Num[i]); } System. out. println ("~~~~~~~~~~~~~~~~~~~~~~~"); //(!) does it look simple or straightforward? Then let's look at the two-dimensional array        intNum1[][] = {{0,1,2},{3,4},{5} };//Note: You can actually think of rows and columns         for(inti =0; i < num1.length; i++) {System. out. Print ("the two-dimensional array output values are:");  for(intj =0; J < Num1[i].length; J + +) {System. out. Print (" "+ num1[i][j]);//Num1[i][j] I only say the first line, such as Num1[0][1] is num1[0] refers to the NUM1 {0,1,2} this object. } System. out. println (); } System. out. println ("~~~~~~~~~~~~~~~~~~~~~~~"); //(!) are you a little unclear when you get here? Come on! Then look at the three-dimensional array.         intNum2[][][] = {                {{0,1,2},{4,5}},                {{6},{7,8},{9}},                {{Ten, One}}        };  for(inti =0; i < num2.length; i++) {System. out. Print ("three-dimensional array output values:");  for(intj =0; J < Num2[i].length; J + +) {                 for(intK =0; K < Num2[i][j].length; k++) {System. out. Print (" "+Num2[i][j][k]); }} System. out. println (); } System. out. println ("~~~~~~~~~~~~~~~~~~~~~~~"); //you've seen the three-dimensional, have you got a clue? or caught the law? To! Come on, another four-dimensional array .        intNum3[][][][] = {                    {                        {                            {0,1,2},{3,4,5,6}                        }                    },                    {                        { {7,8,9},{Ten, One, A, -, -}                        }                    }                }; //assigning or replacing numbers within an array//For example:num3[1][0][0][1] =404;//is to put the 8 initial value (replace) to 404         for(inti =0; i < num3.length; i++) {System. out. Print ("four-dimensional array output values:");  for(intj =0; J < Num3[i].length; J + +) {                 for(intK =0; K < Num3[i][j].length; k++) {                     for(intL =0; L < Num3[i][j][k].length; l++) {System. out. Print (" "+Num3[i][j][k][l]); }}} System. out. println (); }    }}
Similarly
//......

Console output:

One-dimensional array output values:0one-dimensional array output values:1one-dimensional array output values:2~~~~~~~~~~~~~~~~~~~~~~~the two-dimensional array output values are:0 1 2the two-dimensional array output values are:3 4the two-dimensional array output values are:5~~~~~~~~~~~~~~~~~~~~~~~three-dimensional array output values:0 1 2 4 5three-dimensional array output values:6 7 8 9three-dimensional array output values:Ten  One~~~~~~~~~~~~~~~~~~~~~~~four-dimensional array output values:0 1 2 3 4 5 6four-dimensional array output values:7 404 9 Ten  One  A  -  -

Java one-dimensional arrays, two-dimensional arrays, three-dimensional arrays, multidimensional arrays, and so on.

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.