//distance 想要第几个出局.就传入参数为几 private static void josephus(int[] array,int distance){ ArrayList list=new ArrayList(); for (int i : array) { list.add(i); } int index=0; while(list.size()>1){ index=(index+distance-1)%list.size(); System.out.println("出局的号是:"+list.get(index)); list.remove(index); System.out.println(list.toString()); } } public static void main(String[] args) { int[] a = {1,2,3,4,5}; josephus(a, 2); }