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!