JAVA 基础题目
来源:百度知道 编辑:UC知道 时间:2024/07/07 04:33:45
有多少人参加游戏?3
数到哪个数字就退出?7
编号为3的人得到了竹排
package my;
import javax.swing.JOptionPane;
public class Test75 {
public static void main(String[] args) {
String s = JOptionPane.showInputDialog(null, "请输入认数:");
int n = Integer.parseInt(s);
String s2 = JOptionPane.showInputDialog(null, "请输入数到几的倍数退出:");
int tmp = Integer.parseInt(s2);
play(n,tmp);
}
private static void play(int num,int tmp) {
int people = num;// 总人数
int[] person = new int[people];
int count, flag, n, m;
for (n = 0; n < people; n++)
person[n] = n + 1;
count = 0;
flag = 0;
m = 0;
while (count < n - 1) {// 这里想剩下几个人就n减几,按你的要求留1个就减了1
if (person[flag] != 0)
m++;
if (m == tmp) {
person[flag] = 0;
count++;
m = 0;
}
flag++;
if (flag == n)
flag = 0;
}
System.out.print("剩下的人是:");
for (flag = 0;