gpt4 book ai didi

java - feed方法java if语句

转载 作者:行者123 更新时间:2023-12-02 05:59:42 25 4
gpt4 key购买 nike

decHungry() 将饥饿减少 10,incEnergy() 将能量增加 10。我想确保饥饿水平不会超过 0 至负数数字且能量水平不超过 100。我怎么做?

protected void feed() {
System.out.println("\nEating...");
if (hungry <= 90 && hungry >= 0) {
decHungry();
incEnergy();
System.out.println("I've just ate dumplings, my current energy state is " + energy + " and hungry state is " + hungry);
}
else {
System.out.println ("I have ate enough!");
}
}

最佳答案

在调用该函数之前,您需要确保饥饿值大于或等于 10,并且能量小于或等于 90。

if(hungry >= 10){
decHungry();
}
if(energy <=90){
incEnergy();
}

关于java - feed方法java if语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22772224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com