Results 1 to 4 of 4
Thread: Array
- 02-08-2011, 11:45 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 15
- Rep Power
- 0
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
- 02-08-2011, 12:18 PM #2
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Well, where all in that program is anything being "incremented", and which of those is not a simple loop index variable?
- 02-08-2011, 02:01 PM #3
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I don't really know if you are asking a question. It gets incremented values in the for loops.
- 02-08-2011, 06:09 PM #4
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
Similar Threads
-
Variable of an object in an array compared to an element of another array?
By asmodean in forum New To JavaReplies: 23Last Post: 09-07-2010, 08:12 PM -
Trying to make an array list // inserting an element to middle of array
By javanew in forum New To JavaReplies: 2Last Post: 09-06-2010, 01:03 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
Array length and printing out uninitialized array.
By nicolek808 in forum New To JavaReplies: 4Last Post: 09-10-2009, 09:12 AM -
How to add an integer to a array element and the store that backinto an array.
By Hannguoi in forum New To JavaReplies: 1Last Post: 03-31-2009, 06:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks