亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java - 檢查所有數組值,然后檢查 else if

java - 檢查所有數組值,然后檢查 else if

守候你守候我 2022-07-06 17:23:05
我有一個 for 循環,我想檢查數組中的一些值for (Hero myHeroes : heroes) {                if (myHeroes.getCurrentHP() <= 60) {                    world.castAbility(hero, healerHeal, myHeroes.getCurrentCell());                } else if() {                }            }如果我想檢查所有內容,我應該怎么做myHeroes HPs,如果它們不低于 60,請檢查 else-if 部分(對不起,如果我的英語不好)
查看完整描述

2 回答

?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

我想這就是你的意思。


boolean wasAHeroBelowSixtyHp = false;

for (Hero myHeroes : heroes) {

    if (myHeroes.getCurrentHP() <= 60) {

        world.castAbility(hero, healerHeal, myHeroes.getCurrentCell());

        wasAHeroBelowSixtyHp = true;

    }

}

if (wasAHeroBelowSixtyHp) {

    // do something

}


查看完整回答
反對 回復 2022-07-06
?
白衣非少年

TA貢獻1155條經驗 獲得超0個贊

   boolean allOver60 = true;

   for(Hero myHeroes : heroes)

   {

      if ( myHeroes.getCurrentHP() <= 60 )

      {

         world.castAbility( hero, healerHeal, myHeroes.getCurrentCell() );

         allOver60 = false;

      }

   }

   if( allOver60 )

   {

      doSth();

   }


查看完整回答
反對 回復 2022-07-06
  • 2 回答
  • 0 關注
  • 91 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號