标签:
package 约瑟夫环; import java.util.ArrayList; import java.util.List; public class 约瑟夫环 { public static void main(String[] args) { List<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < 8; i++) { list.add(i); } int index = -1; int sp = 3; while (list.size() >= sp) { index = (index + sp) % list.size(); list.remove(index); } for (int i = 0; i < list.size(); i++) { System.out.println(list.get(i)); } } }
标签:
原文地址:http://www.cnblogs.com/felixzh/p/4836691.html