【发布时间】:2014-03-31 21:09:10
【问题描述】:
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!");
}
}
【问题讨论】:
标签: java if-statement methods