Results 1 to 4 of 4
  1. #1
    learner09 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Exclamation Please explain following Program - Two dimensional array

    Hi Friends , I am not getting logic of this program and amused by output , Can anyone explain it clearly step by step -

    public static void main(String args[]) {
    int twoD[][]= new int[4][5];
    int i, j, k = 0;

    for(i=0; i<4; i++)
    for(j=0; j<5; j++) { twoD[i][j] = k; k++;

    }

    for(i=0; i<4; i++) {
    for(j=0; j<5; j++) System.out.print(twoD[i][j] + " ");
    System.out.println();
    }

    Output

    0 1 2 3 4
    5 6 7 8 9
    10 11 12 13 14
    15 16 17 18 19

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    356
    Rep Power
    5

    Default Re: Please explain following Program - Two dimensional array

    Are you familiar with how a loop works? If not, it may be easier to look at a tutorial on loops first, before trying to understand a nested loop, which is what this program involves (a loop inside of a loop). Also, you can take advantage of the System.out.println() function to print out the values of the twoD[][] as its populated as the program runs, that should help you too.

  3. #3
    learner09 is offline Member
    Join Date
    Jan 2013
    Posts
    2
    Rep Power
    0

    Default Re: Please explain following Program - Two dimensional array

    Please explain step by step , I know loops but not able to understand how this works .Would be a good help

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Please explain following Program - Two dimensional array

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Please explain to me this array
    By Mercy in forum New To Java
    Replies: 6
    Last Post: 11-30-2012, 12:42 AM
  2. Replies: 12
    Last Post: 02-08-2011, 02:58 PM
  3. Replies: 1
    Last Post: 02-08-2011, 09:11 AM
  4. about two dimensional array
    By matin1234 in forum New To Java
    Replies: 2
    Last Post: 06-01-2010, 11:09 AM
  5. Multi-dimensional array program-help!
    By bobmasta5 in forum New To Java
    Replies: 13
    Last Post: 03-15-2009, 07:21 PM

Posting Permissions

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