Package WZS. arithmetics; import java. util. tags; // question: there are n people in a circle, ordered by number. When the first person reports the number (from 1 to 3), the person who reports the number 3 leaves the circle and asks the last person who left the number. Public class test_wzs29 {public static void main (string [] ARGs) {system. out. println ("Enter the number of people:"); input = new users (system. in); int member = input. nextint (); // total number of int surplus = member; // number of remaining int COUNT = 0; // report int Index = 0; // The following table indexes Boolean [] array = new Boolean [member]; // The circled for (INT I = 0; I <array. length; I ++) {array [I] = true; // true indicates that the person is still in the circle} // when the remaining number is greater than 1 while (surplus> 1) {If (array [Index] = true) {count ++; // If (COUNT = 3) {array [Index] = false; surplus --; count = 0 ;}} index ++; // when the subscript is equal to the total number of people if (Index = Member) {// re-start number index = 0 ;}} for (INT I = 0; I <array. length; I ++) {If (array [I] = true) {system. out. println ("the remaining persons are:" + I );}}}}
Output result:
Enter the number of students: 123. The remaining persons are: 54.