本文介绍了或者在if语句中使用操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有 我的问题是程序没有正在阅读代码, pre> if(hero.getPos()==(6 | 11 | 16)){ move = new Object [] {Up,Right,Left }; } else { move = new Object [] {Up,Down,Right,Left}; } 当英雄位置为6时,程序仍然转到其他。 > 为什么?是因为操作数吗?如果是,我该如何改变?解决方案使用: if(hero.getPos()== 6 || hero.getPos()== 11 || hero.getPos()== 16)){ 这将做你想要的。 你所做的是比较 hero.getPos(),其结果为(6 | 11 | 16)将执行这些数字之间的位置或。 My problem is that program is not reading codes as i intended "he" would.I haveif (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? 解决方案 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. 这篇关于或者在if语句中使用操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-25 21:15