There is an infinite number of solutions to this puzzle


This is a exercise about Java. I do not how to start to write.

Here is a variant of a famous old puzzle published originally in The Saturday Evening Post , 1926, in a short story entitled "Coconuts," by Ben Ames Williams.

Five sailors, stranded on an island, spent their first day collecting coconuts. In the evening, they put all the coconuts into a single pile and went to sleep.

Sailor One, distrustful of his fellow sailors, woke up during the night, took one fifth of the coconuts, and went back to sleep. Then, a hungry monkey shimmied down a tree and took 1 coconut. A bit later, Sailor Two awoke and took a fifth of the remaining coconuts. Again, the monkey came down and took a coconut. Later, the third, fourth, and fifth sailors did likewise and the monkey took a coconut each time. In the morning, when the five sailors tried to divide the remaining coconuts into five equal piles, they had one coconut left, which they tossed to the ever-hungry monkey. How many coconuts were in the original pile?

There is an infinite number of solutions to this puzzle. Each solution is of the form: number of coconuts = 12495 + 15625 * a, where a=0,1,2,3. . . .

For example, if a=0, then the original number of coconuts is 12495 + 15625 * 0 = 12495; and if a=1 the number is 12495 + 15625 * 1 = 28120. Your job is to write a program that accepts a non-negative integer a (You can assume the user will always input only a non-negative integer), calculates the initial number of coconuts and displays how many coconuts each sailor takes, as well as how many they share in the morning.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: There is an infinite number of solutions to this puzzle
Reference No:- TGS02178376

Now Priced at $20 (50% Discount)

Recommended (94%)

Rated (4.6/5)