I am supposed to create this program that rolls dice 36000 times. After the "dice roll", I am supposed to make a one dimensional array that displays the number of times each possible sum of the dice appears....i.e. 3 was rolled 1,000 times and 4 was rolled 4,000 times etc. Right now, when I run the program, 2-6 have results in the 12,000 range and 7-12 have 1 each. Please Help.
import java.util.Random;
public class RollDice
{
// main method begins program execution
public static void main( String args[] )
{
Random randomNumbers = new Random(); // random number generator
// one-dimensional array of possible sums
int totarray[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int frequency[] = new int[ 13 ]; //array of frequency counters
// roll dice 36000 times;
for ( int rolldie1 = 1; rolldie1 <= 36000; rolldie1++ )
++frequency[ 1 + randomNumbers.nextInt( 6 ) ];
for (int rolldie2 = 1; rolldie2<= 36000; rolldie2++ )
++frequency[ 1 + randomNumbers.nextInt( 6 ) ];
for ( int answer = 0; answer < totarray.length; answer++ )
++frequency[ totarray[ answer ] ];
for ( int tots = 2; tots < frequency.length; tots++ )
System.out.printf( "%d%10d\n", tots, frequency [ tots ] );
}
}
2007-03-27
07:24:18
·
4 answers
·
asked by
Anonymous