import java.util.Scanner;
import java.util.Vector;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.print("请输入总人数:");
int p = input.nextInt();
/**** 初始化人员 ***/
Vector<Integer> v = new Vector<Integer>();// 初始化人员并进行编号
for (int i = 1; i <= p; i++) {
v.add(new Integer(i));
System.out.print(i + " ");
}
/**** 报号 ***/
int num = 0;
while (v.size() > 1) {
for (int i = 0; i < v.size(); i++) {
num++;
if ((num % 3) == 0) {
v.remove(i);
i--;
}
}
}
/***** 结果 *****/
for (int i = 0; i < v.size(); i++) {
System.out.println("\n最后剩下的数是:" + v.get(i));
}
}
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/f2deb48f8c5494eedc6959a928f5e0fe99257e32?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)