我正在制作一个彩票游戏,我试图让控制台允许用户输入 6 个数字,但它只允许用户在将它们与随机数进行比较之前输入 1。
有没有办法让用户在不创建新的 int 变量的情况下输入 6 个数字,而不是将它们与生成的随机数进行比较?
我有一个带有 * 图标的评论突出显示的特定问题。
这是我的代码。
for (int i = 1; i <=6; i++) {
Random run = new Random();
LottoNumbers.add(i);
run.nextInt(49);
//Get Users Lotto Picks
//*Console will not ask for 6 numbers
Scanner scan = new Scanner(System.in);
int lottopick = scan.nextInt();
//prevent user from picking number higher than 49
if (lottopick > 49) {
System.out.println("You canonl pick numbers between 1 and 49");
}
//Compare User selection to random numbers generated
System.out.println("Enter Your Six Numbers between 1 and 49");
if (lottopick == run.nextInt(49)) {
System.out.println("Millionaire");
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
}
else {
System.out.println("You lose");
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
System.out.println(run.nextInt(49));
}
}
请不要继续制作完整的应用程序,因为否则我永远不会学习。谢谢