Home  >  Article  >  Java  >  Java classic programming problem-monkey eating peach problem

Java classic programming problem-monkey eating peach problem

零下一度
零下一度Original
2017-06-25 10:23:204101browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn