开发者

Java int equality inconsistency? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜