package Test; /** * 小孩數數問題,500個小孩,數數,從1開始,數到三退出。求最後一個退出的人原來的位置 * @author huigui * */ public class Count3Quit { public static void main(String[] args) { boolean[] a = new boolean[500]; for (int i = 0; i < a.length; i++) { a[i] = true; } int leftCount = a.length; int index = 0; int num = 0; while(leftCount > 1) { if(a[index] == true) { num++; if(num == 3) { a[index] = false; num = 0; leftCount--; } } index++; if (index == a.length) { index = 0; } } for (int i = 0; i < a.length; i++) { if(a[i] == true) { System.out.println(i); } } } }