标签:
public static void main(String[] args) {
int n = 10;
boolean[] per = new boolean[n];
for (int i = 0; i < per.length; i++) {
per[i] = true;
}
int t = 0, len = per.length;
while (len > 1) {
for (int i = 0; i < per.length; i++) {
if (per[i]) {
t++;
if (t == 3) {
per[i] = false;
System.out.println("出局人为" + i);
t = 0;
len--;//出局把值改变成false,所以手动把len减一,否则一直在while循环内
}
}
}
}
for (int i = 0; i < per.length; i++) {
if (per[i]) {
System.out.println("最后是" + i);
}
}
}
标签:
原文地址:http://www.cnblogs.com/global/p/5367044.html