write a class that simulates rolling a pair of dice 10000 ti

write a class that simulates rolling a pair of dice 10,000 times and counts the number of times doubles are rolled for each different pair of doubles. Using Java

Solution

Hi, Please find my implementation.

Please let me know in case of any issue.

import java.util.Random;

public class DiceSimulation {

  

   public static void main(String[] args) {

      

       // Random Object

       Random random1 = new Random();

       Random random2 = new Random();

      

       int countDoubles = 0; // count number of doubles or 2 appears on both dice\'s face

      

       for(int i=1; i<=10000; i++){

          

           int dice1 = random1.nextInt(6)+1; // random number in range 1-6

           int dice2 = random2.nextInt(6)+1; // random number in range 1-6

          

           if(dice1 == 2 && dice2 == 2)

               countDoubles++;

       }

      

       System.out.println(\"Doubles appears on both dice\'s face: \"+countDoubles);

   }

}

/*

Sample run:

Doubles appears on both dice\'s face: 259

*/

write a class that simulates rolling a pair of dice 10,000 times and counts the number of times doubles are rolled for each different pair of doubles. Using Jav

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site