public class TestMain {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 1; i <= 100; i++) {
list.add(i);
}
int num;
int flag = 0;
// 最终只剩下1人
while (list.size() > 1) {
System.out.println("开始:");
ListIterator<Integer> it = list.listIterator();
while (it.hasNext()) {
num = (int) it.next();
flag++;
if (flag == 4) {
it.remove();
System.out.println("被删除的数字:"+num);
flag = 0;
}
}
}
System.out.println("最后剩下的人:"+list.get(0));
}
}