Points Candy Game

Source: Internet
Author: User

10 children surrounded by a circle of sweets, the teacher assigned to the first child 10, the second child 2, the third child 8, the fourth child 22, the fifth child 16, sixth child 4, seventh children 10, eighth children 6, nineth a child 14, tenth a child 20 blocks. Then all the children at the same time the sugar in their own hands half to the right child, the number of sweets for the odd person can ask the teacher to a piece, asked after such a few adjustments in the hands of the sugar of the number of blocks are as many? How many pieces of sugar each person has?

Public class test2 {public void sharesweet75 ()  {      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;INT[]&NBSP;BOY&NBSP;=&NBSP;{&NBSP;10,&NBSP;2,&NBSP;8,&NBSP;22,&NBSP;16,  4, 10, 6, 14, 20 };            int[] copy = new int[boy.length];            int times = 0;            system.out.print ("Times:"  + times +  " ");            show (Boy);            while  (Allthesame (Boy)  == false)  {//  unequal                 system.arraycopy (BOY,&NBSP;0,&NBSP;COPY,&NBSP;0,&NBSP;10);                for  (int i = 0; i <=  9; i++)  {                    boy[i] = copy[(i - 1 + 10)  % 10] /  2 + copy[i] / 2;                }                times++;                System.out.print ("Times:"  + times +  " ");                show (Boy);                for  (int i = 0; i <= 9; i + +)  {                   if  (boy[i ]&NBSP;%&NBSP;2&NBSP;==&NBSP;1)                         boy[i]++;                }                if  (times > 100)                     break;            }// while            system.out.print ("Times:"  + ++times +  " ");            show (Boy);       }          /**       *  judgment is all equal, only one number returns         */      public boolean allthesame (Int[] a)  {            if  (a == null | |  a.length == 0)  {                return false;           }            if  (a.length == 1)                 return true;              for  (int i = 1; i  < a.length; i++)  {                if  (A[0]&Nbsp;! = a[i])  {                    return false;                }           }            return true;       }        /**       *  display the value of an array         */      public void show (int[]  a)  {           if  (a == null)                system.out.println (" Array = null ");           for  (int  I = 0; i < a.length; i++)  {                system.out.print (a[i] +  " ");            }            System.out.println ();       }  public static void  Main (String[] args)  {// todo auto-generated method stubnew test2 (). ShareSweet75 ();}    }

Run the result as

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/54/6C/wKiom1SBtWax4LgkAANjtvmUcK8552.jpg "title=" 1.png " alt= "Wkiom1sbtwax4lgkaanjtvmuck8552.jpg"/>


650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0003.gif "alt=" J_0003.gif "/>


This article is from a "stroll," blog, please be sure to keep this source http://macxiao.blog.51cto.com/9606147/1586788

Points Candy Game

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.