[英]If statement executing when conditions are false
if (((section[mapposition][mapdirection].getChanceNumber()==0)&&(section[mapposition][mapdirection].isWeaponFound()==false))&&
(naturepart1.equals("rock"))||(naturepart2.equals("rock"))){
// System.out.println(section[mapposition][mapdirection].getChanceNumber());
// System.out.println(section[mapposition][mapdirection].isWeaponFound());
player.addWeapon(section[mapposition][mapdirection].getWeapon());
break;
}
我正在編寫的程序的一部分具有這樣的if語句。 由於某些原因,即使“ getChanceNumber()”返回整數2,以及“ isWeaponFound()”返回true時,該代碼塊仍繼續執行。
我不知道為什么即使條件為false仍然執行此if語句。
謝謝你的幫助。
如果naturepart2.equals(“ rock”)為true,則由於||而執行該語句。 (或)在這些條件之間。 也許將它們括在括號中,以將它們作為附加到&&的二進制語句以及對getChanceNumber和isWeaponFound的檢查進行分組。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.