0

Hi im trying to figure out why my code isn't doing what i want it to do. when i run the code it always does the if statement in the for loop. i changed the logic around but it always does the for loop all the time. im not sure why . thanks for the help

 for (int col =0; col< s ; col++){
 System.out.print(col+ ": ");
 for (int row = 0; row<s; row++)
 {
 x=val[row][col];
 if (table[row][col]==row)
 {
 System.out.print(x+1);
 }
 //System.out.print(val[col][row]+" ");
 if (row+1==s)
 System.out.println();
 }
 }
asked Apr 9, 2013 at 7:16
2
  • 2
    remove the ; after the if statement Commented Apr 9, 2013 at 7:18
  • Abi's right. My question is, because of the tittle, are you comparing Strings in that piece of code? Commented Apr 9, 2013 at 7:23

1 Answer 1

3

You have a semicolon at the end of the if statement, remove it.

 if (x==2);
answered Apr 9, 2013 at 7:18

5 Comments

is there any reason why the loop stops during the 2nd iteration ?
What is the max value for s?, your condition is probably satisfied within the second iteration
i pasted the code on top. i want it to go through every value and count the value but i keep on stoping randomly
2 things - what is val[row][col] and table [row][col]?and second thing please don't modify the original question after it has been answered.it will be better if you post a new question
they stand for rows and columns. i'll post a new question then

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.