Java int equality inconsistency? [closed]
This is driving me insane because it completely violates my attempts to de-buggify it:
int k = keyCode; //keyCode being a variable declared by a keyPress
//in the Proces开发者_开发问答sing library
//k and keyCode are working properly.
if ((k - UP)*500 == 0); //int UP=38;
{
println((k-UP)*500 == 0);
//some other code here
}
The result? "false" (and by removing the '== 0', a number that isn't 0). As far as I know only when you use the arrow keys (k==37,38,39,40; 38 being UP) make this condition true.
Is there any such inconsistency, and what may cause it? (The strange format of the condition is because it fixed a similar problem with the RIGHT key not working correctly with just k==RIGHT).
You have a semicolon after if
, so println
is always executed.
You had a ;
after your if. That makes it an if with an empty statment, followed by an unconditiend block. Just remove the semicolon in the if line.
精彩评论