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();
}
}
brian Chiembrian Chiem
asked Apr 9, 2013 at 7:16
-
2remove the ; after the if statementG.S– G.S2013年04月09日 07:18:44 +00:00Commented 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?Steve Benett– Steve Benett2013年04月09日 07:23:28 +00:00Commented Apr 9, 2013 at 7:23
1 Answer 1
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
brian Chiem
is there any reason why the loop stops during the 2nd iteration ?
Abi
What is the max value for s?, your condition is probably satisfied within the second iteration
brian Chiem
i pasted the code on top. i want it to go through every value and count the value but i keep on stoping randomly
Abi
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
brian Chiem
they stand for rows and columns. i'll post a new question then
lang-java