class Demo1 {
public static void main(String[] args) {
int[] arr = new int[100]; //定义数组,长度100.存储数1-100
for (int i = 0; i < arr.length ;i++) {
arr[i] = i + 1;
}
int sum = 0; //控制循环
int index = 0; //记录索引
int count = 1; //计数器
while (true) { //遍历数组
if (arr[index] != 0 && count != 14) { //遍历的元素不为0并且计数器不为14,计数器加1,索引加1
count++;
if (index == arr.length-1) {
index = 0;
}else {
index++;
}
}else if (count == 14 && arr[index] != 0) { //计数器为14,元素不为0时,为该元素赋值0,剔除元素的计数器(sum)加1,并将索引加1,计数器归值1
arr[index] = 0;
sum++;
count = 1;
if (index == arr.length-1) {
index = 0;
}else {
index++;
}
} else if (arr[index] == 0) { //计数器为14,元素为0时,索引加1.
if (index == arr.length-1) {
index = 0;
}else {
index++;
}
}else if (count != 14 && arr[index] == 0) { //计数器不为14,元素为0,索引加1
if (index == arr.length-1) {
index = 0;
}else {
index++;
}
}
if (sum == 87) {
break;
}
}
for (int i=0; i<arr.length; i++) {
if (arr[i] != 0) {
System.out.println(arr[i]);
}
}
}
} |