猴子吃桃问题


Question

猴子第一天摘下若干个桃子,当即吃了一半,还不过瘾,又多吃了一个,第二天早上又将剩下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下的一半多一个。到第30天早上想再吃时,见只剩下1个桃子了。求第一天共摘了多少



Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
public class A013_Peach {
public static int PeachCount(int day,int count) {
if(day==1) {
return count;
}
else {
return PeachCount(day-1,(count+1)*2);
}
}
public static void main(String[] args) {
int peachNums = PeachCount(30,1);
System.out.println(peachNums);
}
}