package practice;
import java.util.ArrayList;
import java.util.Iterator;
//每14个人去1,有100个人。最后剩的是谁。
public class Demo9 {
public static void main(String[] args) {
int count = 0;
ArrayList<String> list = new ArrayList<String>();
for (int i = 1; i <=100; i++) {
list.add(i+"");
}
System.out.println(method(count, list));
}
private static ArrayList<String> method(int count, ArrayList<String> list) {
ArrayList<String> arrayList = new ArrayList<String>();
Iterator<String> it = list.iterator();
while(it.hasNext()){
count++;
String s = it.next();
if(count%14 != 0){
arrayList.add(s);
}
else{
count = 0;
}
}
if(arrayList.size()>1)
return method(count,arrayList);
return arrayList;
}
}
一样的题 |