public class VarNoOfCols {
public static void main(String[] args) {
int a[][] = new int[3][];
a[0]=new int[3];
a[1]=new int[2];
a[2]=new int[1];
int temp=3;
for(int i =0; i<3;i++) {
for(int k=0;k<temp;k++) {
a[i][k]= k*10;
temp-- ;
}
}
}
}
--- output that I assumed ---- is below ---But this is incorrect.
(0 0) 0 (0 1) 10
(1 0) 0 (1 1) 10
(2 0) 0 (2,1) 10
I know this is incorrect. (My question is - on completing second iteration, "k" is greater than "temp" and when conditon fails it will stop the inner statments and do the next job (what ever it suppose to be).Why am i getting (0,2) = 20 and why i dont see (2,1) = 10 ?
You can see the correct output:
(0 0) 0 (0 1) 10 (0 2) 20
(1 0) 0 (1 1) 10
(2 0) 0
I am a learner and i really appreciate someone's help here. thank you