public class MonkeyEatWildFruit{
public static void main(String[] args) {
int wildFruit = 0;//水果总个数
int wildFruit_day = 0;//每天吃的水果
//根据2楼的倒推设定,最后一次一半的水果
int halfWildFruit = 1;
int monkey = 0;//猴子个数
int day = 5;//吃的天数
while(day>0){
//每天吃的水果是一半+1
wildFruit_day = halfWildFruit +1;
System.out.println("第"+day+"天吃了"+wildFruit_day+"个水果");
wildFruit += wildFruit_day;
//昨天水果的一半,为算上一天的水果做准备
halfWildFruit = halfWildFruit * 2 + 1;
day--;
}
//wildFruit = (int)Math.floor(4.5);
System.out.println("一共的野果数为:"+wildFruit+"个");
}
}