Java basic series-6, two-dimensional array

Source: Internet
Author: User
Class arraydemo {public static void main (string [] ARGs) {int [] [] arr = new int [3] [4]; // defines a two-dimensional array named arr. The two-dimensional array has three one-dimensional arrays, each of which has four elements. System. out. println ("arr =" + ARR); // The result is: arr = [[I @1fb8ee3System.out.println ("arr [0] =" + arr [0]); // The result is: arr [0] = [I @61de33System.out.println ("arr [0] [0] =" + arr [0] [0]); // The result is: arr [0] [0] = 0int [] [] arr2 = new int [3] []; system. out. println ("arr2 =" + arr2); // The result is: arr2 = [[I @61de33System.out.println ("arr2 [0] =" + arr2 [0]); // The result is: arr2 [0] = nullint [] [] arr3 = new int [3] []; arr3 [0] = new int [3]; arr3 [1] = new int [1]; arr3 [2] = new int [2]; system. out. println ("arr3 =" + arr3); // The result is: arr3 = [[I @14318bbSystem.out.println ("arr3 [0] =" + arr3 [0]); // The result is: arr3 [0] = [I @ca0b6System.out.println ("arr3 [0] [0] =" + arr3 [0] [0]); // The result is: arr3 [0] [0] = 0system. out. println ("-----------------------------------"); int [] [] arr4 = new int [3] [4]; system. out. println ("arr4.length =" + arr4.length); // print the length of the two-dimensional array 3; system. out. println ("arr4 [0]. length = "+ arr4 [0]. length); // print the length of the first one-dimensional array in a two-dimensional array 4; system. out. println ("---------------------------------"); int [] [] arr5 = {,}, {,}, {6, 1, 8}; int sum = 0; for (INT x = 0; x <arr5.length; X ++) {for (INT y = 0; y <arr5 [X]. length; y ++) {sum = sum + arr5 [x] [Y] ;}} system. out. println ("sum =" + sum );}}

Exercise: Two-dimensional array Definition

 
Int [] X, Y []; // X one-dimensional, y two-dimensional. // Equivalent to int [] X; int [] Y [];
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.