Question

In: Computer Science

Using Eclipse (RollTwoDice) Write a program RollTwoDice that repeatedly rolls two 6-sided dice until they arrive...

Using Eclipse

  1. (RollTwoDice) Write a program RollTwoDice that repeatedly rolls two 6-sided dice until they arrive at a given desired sum that you read in from user.

    1) the source code (.java file), and

    2) the screenshot of running results of each question

Solutions

Expert Solution

I have written the program using JAVA PROGRAMMING LANGUAGE.

OUTPUT :

CODE :

//imported the require modules

import java.util.Random;

import java.util.Scanner;

//Main class

class Main {

//Main method

public static void main(String[] args) {

int dice1=0,dice2=0,sum=0,userinput;//declared the Integer variables

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

Scanner input = new Scanner(System.in);//scanner object

System.out.print("Please Enter the number inbetween(2 to 12 both inclusive) : ");//print statement

userinput = input. nextInt();//taking user input for the Integer

System.out.print("\nDices combinations : \n");

while(sum != userinput){

dice1 = rand.nextInt(6)+1;//rolling dice1

dice2 = rand.nextInt(6)+1;//rolling dice2

sum = dice1 + dice2 ;

System.out.println(Integer.toString(dice1)+"\t"+Integer.toString(dice2));

}

// Final output to print on the console

System.out.println("\n\nOUTPUT : \nNumber got in dice1 : "+Integer.toString(dice1));

System.out.println("Number got in dice1 : "+Integer.toString(dice2));

}

}

Thanks..


Related Solutions

Alice rolls a pair of fair six-sided dice until a sum of 6 appears for the...
Alice rolls a pair of fair six-sided dice until a sum of 6 appears for the first time. Independently, Bob rolls two fair six-sided dice until he rolls a sum 7 for the first time. Find the probability that the number of times Alice rolls her dice is equal to or within one of the number of times Bob rolls his dice.
Consider rolling two 6-sided dice. What is the probability that at least two of the rolls...
Consider rolling two 6-sided dice. What is the probability that at least two of the rolls have a sum that exceeds 6? at least 7 of the rolls have a sum that is even? exactly three rolls have a sum that equals 5?
A fair 6-sided die is rolled repeatedly. (a) Find the expected number of rolls needed to...
A fair 6-sided die is rolled repeatedly. (a) Find the expected number of rolls needed to get a 1 followed right away by a 2. Hint: Start by conditioning on whether or not the first roll is a 1. (b) Find the expected number of rolls needed to get two consecutive 1’s. (c) Let an be the expected number of rolls needed to get the same value n times in a row (i.e., to obtain a streak of n consecutive...
Bobby rolls 2 fair 6-sided dice and considers it a "success" if the sum of the...
Bobby rolls 2 fair 6-sided dice and considers it a "success" if the sum of the die results is 5 or 6. He performs 4 trials.   Martha tosses 2 fair coins and considers it a "success" if both coins land on "heads." She performs 3 trials. Heather rolls 1 fair 4-sided die and considers it a "success" if he rolls a "1." He performs 5 trials. What is the probability that exactly 2 success occur in all of the combined...
Problem 28. A fair six-sided die is rolled repeatedly and the rolls are recorded. When two...
Problem 28. A fair six-sided die is rolled repeatedly and the rolls are recorded. When two consecutive rolls are identical, the process is ended. Let S denote the sum of all the rolls made. Is S more likely to be even, odd or just as likely even as odd?
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the...
DESCRIPTION Complete the given program to simulate the roll of two 6-sided dice and count the number of rolls of each possible roll value (2 to 12). The number of rolls will be input by the user. Count the rolls of each type and then "draw" a histogram by printing a "*" for each roll of each type. The shape of the histogram will follow the "probability distribution" for large numbers of rolls, i.e., it will show more rolls for...
A fair six-sided die is rolled repeatedly until the third time a 6 is rolled. Let...
A fair six-sided die is rolled repeatedly until the third time a 6 is rolled. Let X denote the number of rolls required until the third 6 is rolled. Find the probability that fewer than 5 rolls will be required to roll a 6 three times.
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice....
In the game of craps, a player (known as the shooter) rolls two fair six-sided dice. The shooter immediately loses if the sum of the dice is 2, 3, or 12 and immediately wins if the sum of the dice is 7 or 11 on the first roll. If the sum is anything else (4, 5, 6, 8, 9, or 10), that number becomes the point and the shooter rolls again. The shooter now wins by rolling that same point...
Throw a pair of fair, six-sided dice, over and over again, until either a 6 or...
Throw a pair of fair, six-sided dice, over and over again, until either a 6 or 10 comes up. What is the probability of event E, that 6 comes up first?
Suppose you roll two twenty-five-sided dice. Let X1, X2 the outcomes of the rolls of these...
Suppose you roll two twenty-five-sided dice. Let X1, X2 the outcomes of the rolls of these two fair dice which can be viewed as a random sample of size 2 from a uniform distribution on integers. (b) List all possible samples and calculate the value of the sample mean ¯(X) and variance (s 2 ) for each sample? (c) Obtain the sampling distribution of X¯ from this list by creating a frequency distribution table. You can create a frequency distribution...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT