The problem of monkeys eating peaches: The monkey picked a few peaches on the first day, ate half of them immediately, and it was not enough, so he ate one more; the next morning, he ate half of the remaining peaches, and more Ate one. From then on, every morning I ate half and one of the leftovers from the previous day. When I wanted to eat more on the morning of the 10th day, there was only one peach left. Find out how many peaches were picked on the first day.
public class Example17 {
public static void main(String[] args) {
int sum = peach(1);
System.out.println("First day of total picks " + sum + "a peach");
}
public static int peach(int day) {
if (day == 10) {
return 1;
} else {
The above is the detailed content of Java classic programming problem-monkey eating peach problem. For more information, please follow other related articles on the PHP Chinese website!