//递归调用
class Person {
private boolean flag = false; //吃饱的标记
private int amount = 100; //有100斤粮食
public void eat() { //吃饭,每调用一次吃一斤
System.out.println("吃粮食,当前的粮食储备量:" + this.amount); //吃饱了
if(flag || this.amount == 0) {
return; //吃完了
}
this.amount -= 1; //每次减少一斤
this.eat(); //继续吃下面的一斤
}
}
public class TestEat {
public static void main(String[] args) {
Person per = new Person();
per.eat();
}
}
转载于:https://www.cnblogs.com/fanren224/p/8457192.html