我试图编写一个程序,选择团队随机管理,但是当我运行它时,每次都得到相同的4个团队而不是不同的团队?随机输出,无法正常工作
我试图让它每次产生一个随机数时都会进入一个数组。然后我会检查该数组,看看数字是否曾经用过。
任何帮助或建议,将不胜感激。谢谢!
import java.util.*;
class Start {
static String[] places = {"Man Utd", "Arsenal", "Aston Villa", "Chelsea",
"Everton", "Fulham", "Liverpool", "Man City", "Newcastle", "Norwich",
"QPR", "Reading", "Southampton", "Stoke", "Sunderland", "Swansea",
"Spurs", "West Brom", "West ham", "Wigan"};
static int[] NA = {21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21};
static Random rand = new Random();
static int RandInt = 0;
static boolean x = false;
static boolean p = false;
static int player = 1;
public static void main(String[] args) {
while (x != true) {
RandInt = rand.nextInt(places.length);
for (int k = 0; k <= NA.length; k++) {
while (p != true) {
if (RandInt == NA[k]) {
RandInt = rand.nextInt(places.length);
} else {
p = true;
NA[k] = RandInt;
}
}
System.out.println("player " + player + " is managing " + places[RandInt]);
player++;
p = false;
if (player >= 5) {
x = true;
System.exit(0);
}
}
}
}
}
int [] NA是什么意思? – geoand
如果您使用答案,请选择它。 – NonSecwitter