I am making a roll the dice game for a project I'm doing for school. I have a random Generator which is called via dice.rollDice()
which then gives the result of the random number.
When I press a key the result of dice.rollDice
is displayed on the console. I need to store the results in an array so far I have the array created
int[] randomNumbers = new int[7];
I'm not sure how to store the results of the dice.rollDice
in the index
I know to store an array the code is randomNumbers[] = dice.rollDice()
is there a more efficient way to do this
Any help is appreciated
Class Dice
:
class Dice {
Random random = new Random(); // assigns random number generator Random();
public int rollDice() {
int output = 1 + random.nextInt(6); //returns a random number between 1 and 6
return(output);
}
}