Hello, im having some trouble with my java assignment.
The Q:
Write a program which will test that a dice is random, i.e. that it is equally likely that any number will appear. E.G The program simulates throwing the dice 6,000 times. The one appears 1003 times, the two, 996 times, etc. Each of the numbers comes up approximately 1000 times, which is what you would expect.
My code so far is as follows:
import java.util.Random;
public class RandomDice
{
public static void main(String [] args)
{
Random randomNumbers = new Random();
int die1;
int die2;
int [] totals = new int[6];
for(int index = 0; index < totals.length; index++)
totals[index]=0;
for(int roll = 1; roll <= 5; roll++)
{
die1 = 1 + randomNumbers.nextInt(6);
die2 = 1 + randomNumbers.nextInt(6);
totals[roll] = die1 + die2;
}
System.out.print("How many times do you want to throw the dice: " + totals );
System.out.println(totals);
for (int k = 2; k < totals.length; k++)
{
System.out.println(k + totals[k]);
}
}
}
When i compile and run the program, this is what i get http://gyazo.com/197559d76628cd4b3daa19463f2b03ac.png
Any help appreciated guys, thx.