1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Alex17521 [72]
3 years ago
10

Write a user input program that simulates a game of a rolling pair of dice. You can create/simulate rolling one die by choosing

one of the integers values of 1, 2, 3, 4, 5, or 6 at randomly. The number that the user chooses will represents the number on the dice after it is rolled. As a hint use Math.random Which will perform the computation to select a random integer between 1 and 6. Assign the value to a variable to represent one of the dice that are being rolled. Perform this operation twice then you will add the results in order to obtain the total roll. Your program should output the number showing on each dice as well as the total roll. For example:
Computers and Technology
1 answer:
balu736 [363]3 years ago
6 0

Answer:

Follows are the program to this question:

public class Main//defining a class  

{

  public static void main(String[] bax)//main method

  {

       int d1,d2,r;   //defining integer variables  

       d1 = (int)(Math.random()*6) + 1;//defining d1 variables that use random method to store a random value  

       d2 = (int)(Math.random()*6) + 1;//defining d2 variables that use random method to store a random value

       r= d1 + d2;//defining r variable that adds d1 and d2 values

       System.out.println("On the first time die will gives: " + d1);//print values with the message

       System.out.println("On the second time die will gives: " + d2);//print values with the message

       System.out.println("The total roll value is: " + r);//print values with the message

   }  

}  

Output:

On the first time die will gives: 6

On the second time die will gives: 1

The total roll value is: 7

Explanation:

In this code three integer variable "d1,d2, and r" is declared, in which the "d1 and d2" variable is used, that uses the random method to hold a random value from 1 to 6 in its variable.

In the next step "r" variable is declared that calculates the addition of the "d1 and d2", and at the last, it uses the print method to print value with the message.  

You might be interested in
Can file extension txt be used in other os
rodikova [14]
Yes, a text file with a .txt extension can be read by Linux/Unix/Mac as they are ASCII unformatted.
6 0
3 years ago
Funny or fascinating web content is said to go _________ when it is shared and re-shared a large number of times over a short pe
beks73 [17]
It is said to go viral?
4 0
3 years ago
What device enables a pc to retrieve a specific row of data from system memory and place it on the external data bus?
Maksim231197 [3]
Memory controller chip is right. 
8 0
3 years ago
Read 2 more answers
A user complains that there are not enough USB ports available on a desktop. What can a technician do to solve the problem?
pickupchik [31]
Install a USB expansion card
3 0
3 years ago
Car rental agencies or taxi services often employ a _______ to service their vehicles on site.
Volgvan
The. answer is B technicians repair things 
4 0
3 years ago
Other questions:
  • How do you delete text from a slide
    14·2 answers
  • How do you return a value from a function?
    6·1 answer
  • Atieno is a musician who records music on her computer. Which devices do you think she would need the most?
    12·1 answer
  • Are engineers who help to develop products and projects by creating technical drawings
    15·1 answer
  • A(n) is the tool that will help you the most when developing the content you will use in your presentation.
    10·1 answer
  • When an object is acted on by unbalanced forces, the object will always
    11·1 answer
  • Write a public member function which replace that replaces one occurrence of a given item in the ArrayBag with another passed as
    14·1 answer
  • When testing a game, why might you consider throttling the game’s “frames per second”?
    9·1 answer
  • The Synonyms submenu offers a list of synonyms for a word. Is it always a good idea to use whatever synonyms are presented on th
    15·1 answer
  • Assume you have written a method with the header num yourMethod(string name, num code). The method's type is ____ .
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!