这基本上是教师用来为每个人进行演示的位置生成随机数的工具。
它不断创造无限循环。我究竟做错了什么?谢谢。
import java.util.Random;
import java.util.Scanner;
public class WhoGoesFirst {
public static void main(String args[]) {
Random random = new Random();
Scanner input = new Scanner(System.in);
int MIN = 1;
int students = 0;
System.out.print("How many students do you have?");
students = input.nextInt();
int comp = random.nextInt(students - MIN + 1) + MIN;
for (int number = 0; number <= students; comp++) {
System.out.println(random);
}
}
}
答案 0 :(得分:0)
您的number
不会在循环中发生变化。试试这个:
for (int number = 0; number <= students; number++) {
int comp = random.nextInt(students - MIN + 1) + MIN;
System.out.println(comp);
}