【java】逢3退1小練習
阿新 • • 發佈:2019-02-07
public class Count3Quit { public static void main (String[] args){ boolean [] arr = new boolean[500]; int len = arr.length; for (int i = 0; i < len ; i++) { arr [i] = true; } int leftCount = len; int countNum = 0; int index = 0; while (leftCount > 0 ){ if (arr[index]==true){ countNum++; if (countNum==3){ countNum = 0; arr[index] = false; leftCount --; } } index++; if (index == len ) { index = 0; } } for (int i = 0; i < len ; i++) { if (arr[i] == true ){ System.out.println(i); } } } }
輸出的是下標值,所以是第i+1個。