约瑟夫环
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)); } } }
欢迎关注微信公众号:大数据从业者