public class DiceSimulation
{
public static void main(String[] args)
{
int dice1, dice2;
int count = 0;
int total = 0;
// Simulating 100000 rolls of dice
for (int i = 0; i < 100000; i++)
{
dice1 = (int)(Math.random()*6 + 1);
dice2 = (int)(Math.random()*6 + 1);
if (dice1 == 1 && dice2 == 1)
{
count++;
}
total++;
}
// Computing the average number of times that two ones are rolled
double average = (double)count / total;
System.out.println("Average number of times that two ones are rolled: " + average);
}
}
|