Question

Write a java code that rolls three dice and counts how many times it takes to...

Write a java code that rolls three dice and counts how many times it takes to get the same numbers


in a series of runs
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

class Main {

public static int DICE()

{

int number=3; // 3 turns

int sum = 0; // get sum

int roll = 0; // randome roll

Random rand = new Random(); // random object

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

{

roll = rand.nextInt(6)+1;

System.out.println("Dist: "+roll);

sum = sum + roll;

}

return sum;

}

public static void main(String[] args)

{

System.out.println(DICE());

}

}

Add a comment
Know the answer?
Add Answer to:
Write a java code that rolls three dice and counts how many times it takes to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Dice Rollers( write java) Write a complete thread class to represent rolling dice. The thread tak...

    Dice Rollers( write java) Write a complete thread class to represent rolling dice. The thread takes a parameter that represents how many dice are being rolled at once and how many times to roll. When the thread is run, it rolls the specified number of dice the specified number of times. The thread counts for how many rolls the number on all dice match. This value is saved as instance data. Write a program to create and run several threads...

  • If a player rolls 2 dice, how do i keep track of the number of times...

    If a player rolls 2 dice, how do i keep track of the number of times a player rolls those 2 dice? Please code in C Please show example code

  • This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no input...

    This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice This problem investigates how...

  • How to write python code that is a dice rolling function that generates random numbers. The...

    How to write python code that is a dice rolling function that generates random numbers. The dice rolling function takes two arguments: the first argument is the number of sides on the dice and the second argument is the number of dice. The function returns the sum of the random dice rolls. For example, if I call roll dice(6,2) it might return 7, which is the sum of randomly chosen numbers 4 and 3. It somewhere along the lines of:...

  • With the use of python IDLE version 3.7.2, use the while loop that iterates 100,000 times....

    With the use of python IDLE version 3.7.2, use the while loop that iterates 100,000 times. In the loop code, roll a pair of dice by generating(and summing) two random numbers in the range 1 through 6. Report to the user how many data points have been generated (i.e how many times the dice have been rolled), as in: successfully simulated 100,000 dice rolls. Create a histogram of the dice rolls showing how many times a 2 was rolled, how...

  • Write a program called CountFlips whose main method flips a coin 100 times and counts how...

    Write a program called CountFlips whose main method flips a coin 100 times and counts how many times each side comes up. Make sure to include comments of what is being done in the code. Verify whether the head comes up or not by calling isHeads method of Coin class. Increment the heads count if head comes up. Increment the tails count if tail comes up. Display the head and tails counts. Print the results SEND AS A TEXT FILE...

  • Write a Java pseudocode for a 2-dice game. This game will roll the two dice together...

    Write a Java pseudocode for a 2-dice game. This game will roll the two dice together for 100 times. In each time, it will display the face values from both dice. The program will count how many times (out of these 100 attempts) did the two dice generate a total point of 10 or above, and display the result at the end. In a word document, PPT file or a PDF file.

  • PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll...

    PYTHON: Dice Rolling Write a script that takes input for the number of dice to roll and for the number of sides for the dice. Roll that many n-sided dice and store the values an array. Take the number of sides of the dice and the number of dice as typed inputs from the user. Output should be a comma separated list of the die numbers with no spaces like this: 6,4,1,3,1 Write a script that will simulate the roll...

  • (MATLAB) Write a program that simulates a dice roll by picking a random number from 1-6...

    (MATLAB) Write a program that simulates a dice roll by picking a random number from 1-6 and then picking a second random number from 1-6.    How many times do you get two 1’s. What many times do you get two 1’s if you simulate 10,000 rolls of a pair of dice?

  • In Yahtzee, 5 standard dice are rolled up to three times on a given turn. A...

    In Yahtzee, 5 standard dice are rolled up to three times on a given turn. A player can choose to save anywhere from 0 - 5 of the dice between rolls 1 and 2 and between rolls 2 and 3, meaning that the player can set aside certain dice before rolling the remaining dice if they choose to do so. Suppose that a given player does not take advantage of saving die rolls and instead rolls all 5 dice each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT