Results 1 to 4 of 4
  1. #1
    aRTx is offline Member
    Join Date
    Mar 2009
    Posts
    27
    Rep Power
    0

    Question How to iterate through two Arrays?

    Hi!

    I'm trying to iterate throught two arrays but I can't do it until now, pls help me if you can!

    This is my problem:
    Let be an array [][] a = [13983816][6]
    00 01 02 03 04 05
    10 11 12 13 14 15
    20 21 22 23 24 25
    30 31 32 33 34 35
    40 41 42 43 44 45

    and another array [][] b = [100000][12];
    00 01 02 03 04 05 06 07 08 09 010 011
    10 11 12 13 14 15 16 17 18 19 110 111
    20 21 22 23 24 25 26 27 28 29 210 211
    30 31 32 33 34 35 36 37 38 39 310 311
    40 41 42 43 44 45 46 47 48 49 410 411
    50 51 52 53 54 55 56 57 58 59 510 511
    60 61 62 63 64 65 66 67 68 69 610 611
    70 71 72 73 74 75 76 77 78 79 710 711
    80 81 82 83 84 85 86 87 88 89 810 811
    90 91 92 93 94 95 96 97 98 99 910 911

    Now I want to compare in this way :
    a[0][0] compare with b[0][0], b[0][1],...,b[0][11]
    a[0][1] compare with b[0][0], b[0][1],...,b[0][11]
    .
    .
    .
    a[0][5] compare with b[0][0], b[0][1],...,b[0][11]
    until now we have compare all of the elemnets of array a[0][x] with elements of array b[0][y]

    Then we must compare in this way:
    a[1][0] compare with b[0][0], b[0][1],...,b[0][11]
    a[1][1] compare with b[0][0], b[0][1],...,b[0][11]
    .
    .
    .
    a[1][5] compare with b[0][0], b[0][1],...,b[0][11]
    then
    a[1][0] compare with b[0][0], b[0][1],...,b[0][11]
    a[1][1] compare with b[0][0], b[0][1],...,b[0][11]
    .
    .
    .
    a[1][5] compare with b[0][0], b[0][1],...,b[0][11]

    ....

    This is what I want!

    I have try to do it with this code, but it does not work properly!

    for(int i=0; i<13983816; i++)
    {
    for(int j=0; j<6; j++)
    {
    for(int k=0; k<i+1; k++)
    {
    for(int l=0; l<12; l++)
    {
    System.out.prilntln(a[i][j] == b[k][l]);

    }
    }
    }
    }

    Can anyone help me? pls....

  2. #2
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default

    Why should we reply to you if you're just going to ignore it as you did with this thread: How to reduce the number of tables??

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,789
    Rep Power
    25

    Default

    it does not work properly!
    Can you show what is output and describe why it is not proper?

    Please reduce the output to enough to show the problem, not for the 10000+ items you show as array bounds.

    Also suggest that the println() statement have more details output such as the values of i, j, k and l

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,728
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by aRTx View Post
    Let be an array [][] a = [13983816][6]
    00 01 02 03 04 05
    10 11 12 13 14 15
    20 21 22 23 24 25
    30 31 32 33 34 35
    40 41 42 43 44 45

    and another array [][] b = [100000][12];
    00 01 02 03 04 05 06 07 08 09 010 011
    10 11 12 13 14 15 16 17 18 19 110 111
    20 21 22 23 24 25 26 27 28 29 210 211
    30 31 32 33 34 35 36 37 38 39 310 311
    40 41 42 43 44 45 46 47 48 49 410 411
    50 51 52 53 54 55 56 57 58 59 510 511
    60 61 62 63 64 65 66 67 68 69 610 611
    70 71 72 73 74 75 76 77 78 79 710 711
    80 81 82 83 84 85 86 87 88 89 810 811
    90 91 92 93 94 95 96 97 98 99 910 911
    If those are your real matrix values then you don't need such huge matrixes at all because every element is functionaly dependent on the row and column index values, e.g. a[i][j] == 10*i+j and b[i][j]= ((j < 10)?10:100)*i+j.

    kind regards,

    Jos

Similar Threads

  1. Iterate Text File
    By Boaz in forum New To Java
    Replies: 5
    Last Post: 03-17-2009, 09:55 AM
  2. Replies: 1
    Last Post: 10-17-2008, 11:18 AM
  3. problem with <logic:iterate> tag looping
    By tsaswathy in forum Web Frameworks
    Replies: 0
    Last Post: 09-27-2008, 01:13 PM
  4. Using Enumeration to iterate through Hashtable
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-15-2008, 09:44 AM
  5. iterate HashMap with logic
    By Heather in forum Web Frameworks
    Replies: 2
    Last Post: 07-03-2007, 10:47 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
  •