Thread: How to iterate through two Arrays?

1. Member
Join Date
Mar 2009
Posts
27
Rep Power
0

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. Senior Member
Join Date
May 2010
Posts
436
Rep Power
4
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. 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. Originally Posted by aRTx
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

Posting Permissions

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