Question

In: Computer Science

A dice has 6 face values: one, two, three, four, five, and six. If you roll...

A dice has 6 face values: one, two, three, four, five, and six. If you roll a dice, you will see one of them with equal opportunity. Write a java program which rolls a dice 6000 times. The ideal case is that each face value will appear 1000 times. However, your program should give slightly different numbers.

Solutions

Expert Solution

The code is given below

import java.util.Random;
public class MyClass {
public static void main(String args[]) {
int[] arr=new int[6];
//to store the counts where 0 represents 1 on dice and 5 represents 6 on dice;
for(int i=0;i<6;i++)arr[i]=0;
Random r=new Random();
for(int i=0;i<6000;i++){
int rollValue=r.nextInt(6);
arr[rollValue]++;
}
for(int i=0;i<6;i++){
System.out.println("Count of "+(i+1)+" is "+arr[i]);
}
}
}

The output is


Related Solutions

. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6...
. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6 and you win if some number appears 3 or more times. For example, if you roll: (3,3,5,4,6,6) then you lose. If you roll (4,1,3,6,4,4) then you win. What is the probability that you win this game?
You roll a six-faced dice and observe the number of dots on the top face. (a)...
You roll a six-faced dice and observe the number of dots on the top face. (a) Specify the appropriate sample space S of the random experiment. (b) Give an example of a partition of S. (Proof is unnecessary.) (c) Give an example of a probability mass function (pmf) for S.
Roll three (6-sided) dice. Let X denote the maximum of the values that appear. a. Find...
Roll three (6-sided) dice. Let X denote the maximum of the values that appear. a. Find P(X=1).?? b. Find P(X=2).?? c. Find P(X=3). d. Find P(X=4).?? e. Find P(X=5).? f. Find P(X=6). [Hint: It might be helpful to first find the values of P(X?x).]
Roll two fair dice. Each die has six faces. A. Let A be the event that...
Roll two fair dice. Each die has six faces. A. Let A be the event that either a 3 or 4 is rolled first followed by an odd number. P(A) =  Round your answer to two decimal places. B. Let B be the event that the sum of the two dice is at most 7. P(B) =  Round your answer to two decimal places. C. Are A and B mutually exclusive events? (Yes or No) D. Are A and B independent or...
Design an application that uses the C# random generator to randomly roll a six face dice...
Design an application that uses the C# random generator to randomly roll a six face dice ( no 1 - no 6) . If the user rolled a 3, the user gets to roll the six face die again. You must use a switch statement to write the result /s of the random dice roll/s to the screen. Hint: You should have nested switches in your program Using: Console App(.NET Framework)
You roll two six-sided even dice. What is the probability that you get a score of...
You roll two six-sided even dice. What is the probability that you get a score of at least 11? a. 2/11 b. 1/12 c. 1/18 d. 1/6 
 
 You toss a fair coin 3 times in a row. What is the probability of getting at most two heads? a. 3/4 b. 1/4 c. 3/8 d. 7/8
If I roll two 6 sided dice, one yellow and one clear, what are the possible...
If I roll two 6 sided dice, one yellow and one clear, what are the possible microstates, and what is the Gibbs entropy at 298.15 K? What is the entropy if the dice are indistinguishable? Calculate the entropy if one can only measure the sum of the dice instead of their individual values.
You roll two 6-sided dice numbered 1 through 6. Let A be the event that the...
You roll two 6-sided dice numbered 1 through 6. Let A be the event that the first die shows the number 3, let B be the event that the second die shows a 5, and let E be the event that the sum of the two numbers showing is even. Compute P(A)and P(B)and then compute P(AlB). What does this tell you about events A and B?Hint: Remember that the sample space has 36 outcomes! Compute P(ElA)and compute P(E). What does...
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the...
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the 3 dice is less than 13, then the player will receive a prize of $ 70. Otherwise, you lose the $13. a. Find the expected value of profit.
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2...
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2 or 3 b) 6 and 4 c) At least one 5 d) Two of the same number (two 1s, or two 2s, or two 3s, etc.) e) An even number on both dice f) An even number on at least one die
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT