我正在尝试加载两个数组。表示掷骰子的可能结果(1-6)的。第一个数组加载第一个骰子结果和第二个数组.....我正在努力将两个数组保持在一个循环中,以管理骰子滚动的次数,而不是生成重复的结果。相信我需要在每一卷之间重新播种,任何帮助都会非常感激。
当前输出:骰子1:5,骰子2:5骰子1:3,骰子2:3第一个骰子:1第二个骰子:1第一个骰子:6第二个骰子:6第一个骰子:6第二个骰子:6第一个骰子:2第二个骰子:2骰子1:5,骰子2:5第一个骰子:2第二个骰子:2第一个骰子:1第二个骰子:1第一个骰子:1第二个骰子:1第二次滚动总是匹配第一次
我写的如下:
int min = 1;
int max = 6;
for (int i = 0; i < 10; i++)
{
Random rand;
rand = new Random();
int randomNumber = rand.nextInt(max) + min;
diceOne[i] = randomNumber;
System.out.print("Dice one: ");
System.out.print(diceOne[i] + " ");
int randomNumber2 = rand.nextInt(max) + min;
diceTwo[i] = randomNumber2;
System.out.print("Dice two: ");
System.out.print(diceOne[i]);
System.out.println();
diceTwo从未使用过。试试下面的代码
int randomNumber = rand.nextInt(max) + min;
diceOne[i] = randomNumber;
System.out.print("Dice one: ");
System.out.print(diceOne[i] + " ");
int randomNumber2 = rand.nextInt(max) + min;
diceTwo[i] = randomNumber2;
System.out.print("Dice two: ");
System.out.print(diceTwo[i]); //System.out.print(diceOne[i]);
System.out.println();
嗯,看起来你两次都打印出了diceOne[i]