public static void main(String
[] args
) {
Scanner input
= new Scanner(System
.in
);
System
.out
.println("请输入人数:");
int renCount
= input
.nextInt();
int rens
[] = new int[renCount
];
for (int i
= 0; i
< rens
.length
; i
++) {
rens
[i
] = i
+1;
}
int count
=0;
int index
=0;
while(renCount
>1) {
if(rens
[index
]!=0) {
count
++;
if(count
==3) {
count
=0;
rens
[index
]=0;
renCount
--;
}
}
index
++;
if(index
==rens
.length
) {
index
= 0;
}
}
for (int i
= 0; i
< rens
.length
; i
++) {
if(rens
[i
]!=0) {
System
.out
.printf("原来排在第"+(i
+1)+"个位置的人留下了。");
break;
}
}
}
转载请注明原文地址:https://tech.qufami.com/read-147.html