I found some Java videos on the internet and learned a bit. The teacher told a question, there are 500 children pulled into a circle, beginning 123123 Such a count, the number to 3 of the children out of the circle, asked: The last child's position is the number.
I followed the teacher's thinking wisp, and then I blind dozen code, feeling very complex, so the code copy down, left for later review with. (Results: 435)
//Number 3 back 1 Public classcount3quit1 { Public Static voidMain (string[] args) {boolean[] arr=Newboolean[ -]; for(inti =0; i < arr.length; i++) {Arr[i]=true; } intLeftcount = Arr.length;//number of remaining children initialized intCountnum =0;//Counter (number 3 back 1) Initialize intindex =0;//Subscript Value Initialization while(Leftcount >1){ if(Arr[index] = =true) {Countnum++; if(Countnum = =3){//number of counters to 3Arr[index] =false;//from true to false means to let the child quitCountnum =0;//Counter 0Leftcount--;//number of children remaining-1}} Index++;//Subscript Value if(index = = arr.length) {//(0-499) When the mark is No. 500, a circle cycle is complete, start again cycle, initialize subscriptindex =0; } } for(inti =0; i < arr.length; i++){ if(Arr[i] = =true) {System. out. println (i);//Print the location of the last Child Left } } } }
Number 3 back 1