Results 1 to 4 of 4

Thread: Array

  1. #1
    JAVA03 is offline Member
    Join Date
    Nov 2010
    Posts
    15
    Rep Power
    0

    Question 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

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, where all in that program is anything being "incremented", and which of those is not a simple loop index variable?

  3. #3
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I don't really know if you are asking a question. It gets incremented values in the for loops.

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    It is a hint. Take another, close look at the code. There is a ++ that is not a loop counter.

Similar Threads

  1. Replies: 23
    Last Post: 09-07-2010, 08:12 PM
  2. Replies: 2
    Last Post: 09-06-2010, 01:03 AM
  3. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  4. Array length and printing out uninitialized array.
    By nicolek808 in forum New To Java
    Replies: 4
    Last Post: 09-10-2009, 09:12 AM
  5. Replies: 1
    Last Post: 03-31-2009, 06:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •