Write Java that generates a random integer n between 1 and 1

Write Java that generates a random integer n between 1 and 1000, simulates rolling a 6-sided die n times, and computes and displays (floating-point) average of the numbers rolled and the count of the odd number rolled

Solution

package chegg;

public class simulateDice {

   public static void main(String args[])

   {

       int n = (int) (Math.random()*1000);

       int sum=0,tmp=0,sum2=0;

       for(int i=0;i<n;i++)

       {

           tmp = (int) (Math.random()*6);

           if(tmp%2==1)

           {

               sum2+=tmp;

           }

           sum+=tmp;

           //tmp++;

       }

       System.out.println(\"The average value of the dice is \"+(sum*1.0)/n);

       System.out.println(\"The sum of all odd numbers is \"+sum2);

      

   }

}

 Write Java that generates a random integer n between 1 and 1000, simulates rolling a 6-sided die n times, and computes and displays (floating-point) average of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site