Or operand with int in if statement

前端 未结 12 1954
傲寒
傲寒 2021-01-25 07:45

My problem is that program is not reading codes as i intended \"he\" would.

I have

if (hero.getPos() == (6 | 11 | 16)) {
    move = new Object[] {\"Up\",         


        
12条回答
  •  时光取名叫无心
    2021-01-25 08:18

    Use:

    if (hero.getPos() == 6 || hero.getPos() == 11 || hero.getPos() == 16)) {
    

    This will do what you want.

    What you did is comparing hero.getPos() with the result of (6|11|16) which will do bitwise or between those numbers.

提交回复
热议问题