Hi,
i am learning multi dimensional array and struggling to understand the output which i am getting from one of the program which i have written by seeing an example from a book. The program goes like this,
// Demonstration of Two Dimensional Array class TwoDArray { public static void main(String args[]) { int twoD[] [] = new int[4] [5]; int i, j, k = 0; for(i=0; i<4; i++) for(j=0; j<5; j++) { twoD[i][j] = k; k++; } for(i=0; i<4; i++) { for(j=0; j<5; j++) System.out.print(twoD[i][j] + " "); System.out.println(); } } }
The out put, which i am getting is,
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
i am confused that, why first two rows should contain only 5 digits and the las two rows should contain 6 digits. Also, how the numbers are incremental.
Please help me to understand in a simple manner, as the explaination given in the book is not convincing me...
--- Update ---
My bad! My apologies that i have overlooked into the result. Infact all the rows contain 5 digits.So my only doubt is now, how the numbers are incremental and what is this got something to do with for loop.