Question: Java code Description In a kindergarten class, there are n children sitting in a circle facing their teacher in the center. Each child initially has


Java code
Description In a kindergarten class, there are n children sitting in a circle facing their teacher in the center. Each child initially has an even number of candy pieces. When the teacher blows the whistle, each child simultaneously gives half of his or her candy pieces to the neighbor to the left. Any child who ends up with an odd number of pieces is given another piece by the teacher. Then the teacher blows the whistle again, unless all the children have the same number of candies, in which case the game stops. Can this game go on forever or will it eventually stop to let the children go on with their lives? We will assume that if the game does not end after 100 whistles, then that game will go on forever The input consists of data sets of two lines for each data set. The first line contains one integer indicating n (2 S n s 100), the number of children sitting in a circle. The second line consists of n even positive integers each representing the initial number of candy pieces for each child in clockwise order around the circle. You may assume that all initial number of candy pieces is even. Your program should continue accepting data sets until a zero is input for the number of children. At this point the program should terminate without any further output produced. The output will consist of two types of lines. If the game stops, output the number of whistle blows that take place until each child has an equal number of candy pieces in the form: "xx whistle blows" where xx is the number of whistle blows. If the game does not end after 100 whistles, output "Game goes on forever". Fully qualified class names are listed below: edu.ben.homeworks.homework6.Homework6.java Packaging: edu.ben.homeworks.homework6.Homework6Test.java EXAMPLE INPUT 6 8 32 10 2 48 34 4 1000 100 10 2 EXAMPLE OUTPUT 17 whistle blows 19 whistle blows
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
