Multi dimensional array

description of image


Create a 2D array


Here’s is how we can create multidimensional arrays:


Int[][] data = new int[3](4];


Here, data is a two-dimensional array where each 3 elements of the array is also an array that has 4 elements. Hence, the array can hold 12 elements in total.


Initialize Two Dimensional Arrays


Here is how we can initialize a 2D array.


Int[][] data = { {2, 3, 5},


{7, 14, 21, 28},

{3, 5, 7, 9} };


Here, data is a 2D array. We can see each element of the array is an array itself.


Similar to a one-dimensional array, we use indexes to access elements of a 2D array.



Print 2D Array Elements


● We can use nested loops to print elements of a 2D array. Here’s an example.



Quiz


Question Text