public class Demo {
public static void main(String[] args) {
// 键盘输入,得到玩游戏的人数
Scanner sc = new Scanner(System.in);
System.out.println("输入人数:");
int n = sc.nextInt();
// 定义数组,长度为键盘输入值
int[] player = new int[n];
int num = 0;// 每个人要喊的数字
int i = 0;// 索引,第几个人了
int out = 0;// 出局人数
while (out < n - 1) { // 条件是out小于玩游戏的人数-1
if (player[i] == 0) { // player[i]==0保证不是被淘汰的人
num++;
if (num == 7) { // 当该喊7时,这个数可以改,这个人被淘汰,并且改变他再数组中的值,将要喊的数字改为0,新的一轮喊数
out++;
player[i] = 1;
num = 0;
}
}
i++;
if (i == n) { // 当i==n时,表示第一轮最后一个人,将n改为0,开始下一轮
i = 0;
}
}
// 遍历数组,通过判断再数组中的值来确定谁是被留到最后的那个人
for (int n1 = 0; n1 < player.length; n1++) {
if (player[n1] == 0) {
System.out.println("游戏最后剩下第" + (n1 + 1) + "个同学!");
}
sc.close();
}
}