Or operand with int in if statement
问题 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", "Right", "Left"}; } else { move = new Object[] {"Up", "Down", "Right", "Left"}; } When hero position is 6, the program still goes to else. Why is that? Is it because of operands? If yes, how should i change it? 回答1: Use: if (hero.getPos() == 6 || hero.getPos() == 11 || hero.getPos() == 16)) { This will do what you want. What you did is comparing