比如数数到3的倍数,干掉
public static int luckyNum(int num) { ArrayList<Integer> list=new ArrayList<Integer>(); for (int i = 0; i < num; i++) { list.add(i); } int count=1; for (int i = 0; list.size() != 1; i++) { if (count > list.size()) { i = 0; } if (count % 3 == 0) { list.remove(i); i--;//此处关键,for循环中记得删除元素后--下,因为新元素会占据刚刚删掉的位置,得回来重新判断一下 } count++; } return list.get(0); }