Joseph Ring: Known n individuals (denoted by number 1,2,3...N respectively) sit around a round table. From the number of people who numbered K, the man who counted to M is out of the way, and his next man counts off from 1, and the person counting to M is out of the way; Repeat until all the people around the table are out.
Knowledge Supplement:
The list interface has two main implementation classes, ArrayList and LinkedList classes. Duplicate elements are allowed in the list collection, unlike set sets, where the elements in the list collection are ordered, and the elements in the list collection can be retrieved based on the index location, the first element to be added is indexed as 0, the second is 1, and so on
Importjava.util.ArrayList; Importjava.util.List; ImportJava.util.Scanner; Public classtest{ Public Static voidMain (string[] args) {Scanner Scanner=NewScanner (system.in); System.out.print ("Please enter the total number of people:"); intTotalnum =Scanner.nextint (); System.out.print ("Please enter the size of the count:"); intCyclenum =Scanner.nextint (); Yuesefu (Totalnum, cyclenum); } Public Static voidYuesefu (intTotalnum,intcountnum) { //number of people initializedlist<integer> start =NewArraylist<integer>();//Create a list collection, and the collection holds an integral type
The correct way to create 13 numbers is as follows:
//list<integer> list=new arraylist<integer> (new Integer); for(inti = 1; I <= totalnum; i++) {start.add (i); Add elements to the collection like}//counting starting from the first K intK = 0; while(Start.size () >0) {k= k +Countnum; //Count toThe index position of the person mk = k% (Start.size ())-1; //System.out.println (Start.size ()); //Judging whether to the end of the team if(K < 0) {System.out.println (Start.get (start.size ()-1)); System.out.println (3333); Start.remove (Start.size ()-1); K= 0; } Else{System.out.println (Start.get (k));//Get the corresponding value by index Start.remove (k); Delete the element at the specified location}} } }
Joseph question Java