public class test { public static void main(String[] agrs) { int [][] a1 = { { 1,2,3},{4,5,6},{7,8,9}}; for(int i=0;i<3;i++) { for(int j=0;j<3;j++) { System.out.println(a1[j][i]); } } } }
Ans: at run time the values for a1 are 00 -------- 1 01 ---------2 02---------3 Like this we have to get the answer. But output for this question coming as 147258369 Can any one say why this is happening?
I can agree for given answers but While creating the Array I didn�t mention any reference names like i or j. so why complier is assuming like first reference is �i� and second reference is �j� ?
The compiler is not assuming this The interpreter is assuming this because this is what you tell him to assume.
Think a bit about it.
With the code you show you are actually going through the table [1,2,3] [4,5,6] [7,8,9] in the order 1->4->7->2->5->8->3->6->9 while you want to go that way: 1->2->3->4->5->6->7->8->9
Hope this helps. [ February 15, 2006: Message edited by: Peter Petrov ]