-
Array
Hi,please explain me this program how it is getting incremented.
class TwoDAgain
{
public static void main(String[] args)
{
int j,i,k=0;
int twod[][] =new int [4][];
twod[0]= new int[1];
twod[1]= new int[2];
twod[2]=new int[3];
twod[3]=new int[4];
for (i=0;i<4;i++)
for (j=0;j<i+1 ;j++ )
{
twod[i][j]=k;
k++;
}
for(i=0;i<4;i++){
for (j=0;j<i+1 ;j++ )
System.out.print(twod[i][j]+ " ");
System.out.println();
}
}
}
out put is:
0
1 2
3 4 5
6 7 8 9
thanks
-
Well, where all in that program is anything being "incremented", and which of those is not a simple loop index variable?
-
I don't really know if you are asking a question. It gets incremented values in the for loops.
-
It is a hint. Take another, close look at the code. There is a ++ that is not a loop counter.