约瑟夫
1 ArrayList list=new ArrayList(); 2 for(int i=1;i<8;i++) 3 list.add(i); 4 final int which=8; 5 int countNum=0; 6 int index=0; 7 8 while(list.isEmpty()==false) 9 { 10 countNum=countNum+1; //计数用的 11 if(countNum==which) //数几个数 12 { 13 countNum=0; 14 System.out.print(" "+list.remove(index)); 15 if(index==list.size()) 16 index=0; 17 continue; 18 } 19 index++; 20 if(index==list.size()) 21 index=0; 22 }