public class LckBoy {
public static void luck(int num) {
int[] list = new int[num];
for(int i = 0; i < list.length; i++) {
list[i] = i + 1;
}
int count = 1;//记录下标
while(list.length > 2) {
int size = 0;
for(int i = 0; i< list.length; i++) {
if(count % 2 == 0)
list[i] = 0;
else {
size++;
}
count++;
}
int[] luckBoys = new int[size];
int index = 0;
for(int i = 0; i < list.length; i++) {
if(list[i] != 0)
luckBoys[index++] = list[i];
}
list = luckBoys;
}
System.out.println("幸运儿:" + Arrays.toString(list));
}
public static void main(String[] args) {
luck(10);
}
}