2D Array TA.Rawan
Print 2D array This Photo by Unknown Author is licensed under CC BY-SA-NC
Initialize 2D Array: “twodArray ” int [][] twodArray ={ {2,1,5}, {32,5,4} }; Column j[0] j[0] j[1] j[1] j[2] i[0] 5 1 2 4 32 ROW i[1]
Which means length of row in this example for first row = 3 To print 2D Array: Which means length of row in this example for first row = 3 for (int i = 0; i < twodarray.length; i++) { for (int j = 0; j < twodarray[i].length; j++) System.out.print(twodarray[i][j] + “ ” ); } System.out.println();
To print 2D Array: i=0 j=0 j=0 j=0 Is j <3 Is j <3 j=1 Is i<2 j=0 j=0 j=0 Is j <3 Is j <3 j=1 Is j <3 j=2 Is j <3 j=3 Is j <3 j[0] j[1] j[2] i[0] 2 1 5 Repeat the same steps for i=1, then when i= 2 the condition is false 2<2
Thank you. Any questions?