Hello there.i have to find if elements of a row are equal to elements of another row.this is my code but it wont work.
when k becomes 1, i want the for loop at i to start with i=2; can you help ?????

``````int b[][]={
{1,2,23,4,5},
{6,1,8,9,28},
{11,12,13,14,15},
{1,17,18,19,20},};
for(int k=0;k<3;i++){// when k increases with 1 i want also i to increase with 1.meaning, when k becomes 1, for loop with start with i=2;
for(int l=0;l<5;l++){
for(int i=1;i<4;i++){
for(int j=0;j<5;j++){
if(b[k][l]==b[i][j]){
System.out.print(b[k][l]+" ");
}
}
}
}
}
}
}
``````

Hello there.i have to find if elements of a row are equal to elements of another row.this is my code but it wont work.
when k becomes 1, i want the for loop at i to start with i=2; can you help ?????
int b[][]={
{1,2,23,4,5},
{6,1,8,9,28},
{11,12,13,14,15},
{1,17,18,19,20},};
for(int …

## All 4 Replies

Hello there.i have to find if elements of a row are equal to elements of another row.this is my code but it wont work.
when k becomes 1, i want the for loop at i to start with i=2; can you help ?????
int b[][]={
{1,2,23,4,5},
{6,1,8,9,28},
{11,12,13,14,15},
{1,17,18,19,20},};
for(int k=0;k<3;i++){// when k increases with 1 i want also i to increase with 1.meaning, when k becomes 1, for loop with start with i=2;
for(int l=0;l<5;l++){
for(int i=1;i<4;i++){
for(int j=0;j<5;j++){
if(b[k][l]==b[j]){
System.out.print(b[k][l]+" ");
}
}
}
}
}
}
}

why not in your for statement with 'i' do:

``````for(int i=1;i<4;i++){
if(k==1) i=2;
....``````

[EDIT] sorry how dumb of me you'll need to add this:

``````if(count==0) {
if(k==1) i=2;
count++;
}``````

and then declare the integer count as static in your main class and initialize it to 0 or else the for statement will go into a never ending loop

[EDIT] I just thought about something depending on how you want your output to look i guess you could also use:
for(int i=k+1;i<4;i++) this would produce: 1 1 1 which might be more what you want

thx men ;)
i will try it :)

thx men ;)
i will try it :)

btw ,change you for(int k= 0; k < 3;i++) to for(int k= 0; k < 3;k++) or else it will never work

thx.it works now :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.