Home  >  Article  >  Java  >  Java classic programming questions divided into peaches

Java classic programming questions divided into peaches

怪我咯
怪我咯Original
2017-06-25 10:25:131997browse

There are several piles of peaches on the beach, and five monkeys come to divide them. The first monkey divided the pile of peaches into five equal parts. If there was one more, the monkey threw the extra one into the sea and took one. The second monkey divided the remaining peach into five equal parts, and there was one more. It also threw the extra peach into the sea and took away one. The third, fourth, and fifth monkeys all did this. How many peaches were there on the beach?

public class Example41 {
    public static void main(String[] args) {
        number();
    }
    public static void number() {
        int i, m, j = 0, k, count;
        for (i = 4; i < 10000; i += 4) {
            count = 0;
            m = i;
            for (k = 0; k < 5; k++) {
                j = i / 4 * 5 + 1;
                i = j;
                if (j % 4 == 0)
                    count++;
                else
                    break;
            }
            i = m;
            if (count == 4) {
                System.out.println("原有桃子 " + j + " 个");
                break;
            }
        }
    }
}


The above is the detailed content of Java classic programming questions divided into peaches. 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