Re: Dice Rolling Simulation
I think I may have a little more information but now I'm getting a dice1 cannot be initialized and I do not believe I am totalling up the two correctly to store them back into the array.
Quote:
// Dice Rolling
import java.util.Random;
public class DiceRolling
{
public static void main( String[] args)
{
Random randomNumbers = new Random(); // Generates random numbers
int[] array = new int[ 13 ]; // Declares the array
int dice1;
int dice2;
int total;
//Roll the die 36,000 times
for ( int roll = 1; roll <=36000; roll++ )
dice1 = 1 + randomNumbers.nextInt ( 6 );
dice2 = 1 + randomNumbers.nextInt ( 6 );
total = dice1+dice2;
++array[total];
System.out.printf( "%s%10s\n", "Face", "Frequency" );
// outputs array values
for ( int face = 1; face < array.length; face++ )
System.out.printf( "%4d%10d\n", face, array[ face ] );
} // end main
} // end class DiceRolling
Re: Dice Rolling Simulation
Solved:
Code :
//Roll the die 36,000 times
for ( int roll = 1; roll <=36000; roll++ )
{
int die1 = 1 + randomNumbers.nextInt ( 6 );
int die2 = 1 + randomNumbers.nextInt ( 6 );
int total = die1 + die2;
++array[total];
}