Skip to content

Commit 9e71b6c

Browse files
committed
Update Creating and Initializing 1D,2D Arrays
1 parent ea56de5 commit 9e71b6c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Creating and Initializing 1D,2D Arrays

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public static void main(String[] args) {
1717
// Initialzing 2d array. Doing initialization and creation in the same step, does not require 'new' operator.
1818
String[][] TwoDArray = {{"hello","world"},{"hi","bye"},{"me","tu"},{"aapli","aapla"}}; // 4*2 array
1919
int[][] intTwoArray = {{1,2,3},{4,5,6},{8,9,10},{11,12,13},{14,15,16}}; // 3*5 array
20+
//Use 2D array
21+
int[][] maze = new int[6][6];
22+
maze[0] = new int[] { 1, 1, 0, 0, 0, 0 };
23+
maze[1] = new int[] { 0, 1, 0, 0, 0, 0 };
24+
maze[2] = new int[] { 0, 1, 0, 1, 1, 1 };
25+
maze[3] = new int[] { 1, 1, 1, 1, 0, 1 };
26+
maze[4] = new int[] { 0, 1, 0, 0, 0, 1 };
27+
maze[5] = new int[] { 0, 1, 0, 0, 0, 1 };
2028

2129
// Accessing number of rows and columns in multidimentional arrays
2230
int rows = TwoDArray.length; // Gives number of rows

0 commit comments

Comments
 (0)