Java Implementation Algorithm for children's digital games

Source: Internet
Author: User
Package second; import java. util. arrayList; public class second {/*** Number of children multiple children in a game circle, number by number, and exit when the number is counted to a specified number, continue to the next number starting from 1, so that the return loop is used to find the last left child ** @ param args */public static void main (String [] args) {// TODO Auto-generated method stub // the specified number int num = 4; // the specified number of children int person [] = {1, 2, 3, 4, 5}; // starting from the first few children int beginperson = 1; // array subscript int count = beginperson-1 to be deleted; ArrayList <Integer> ai = new ArrayL Ist <Integer> (); for (int I = 0; I <person. length; I ++) {ai. add (person [I]);} int numperson = CounGameMethod (num, ai, beginperson, count); System. out. println ("+" + numperson + "");} private static int CounGameMethod (int num, ArrayList <Integer> person, int beginperson, int count) {if (person. size ()! = 1) {if (beginperson = num) {System. out. println ("th" + person. remove (count) + "children out"); if (count = person. size () {count = 0;} beginperson = 1;} else {beginperson ++; if (count <person. size ()-1) {count ++;} else {count = 0 ;}} return CounGameMethod (num, person, beginperson, count);} else {return person. get (0 );}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.