0

hello everyone,
i am very new in java.this is why i need some help from you.i hope you will help me by solving the following problem:

write a program that simulates rooling a pair of dice. you can simulate rooling one die by choosing one of the integers 1, 2, 3, 4, 5, or 6 at random. the number you pick represents the number on the die after it is rolled. the expression
(int)(Math.random()*6) + 1
does the computation you need to select a random integer between 1 and 6. you can assign this value to a value to a variable to represent one of the dice that are being rolled. do this twice and add the results together to get the total roll. your program should report the number showing on each die as well as the total roll. for example:
the first die comes up 3
the second die comes up 5
your total roll is 8


regards,
shantuli :o

2
Contributors
1
Reply
7
Views
12 Years
Discussion Span
Last Post by rickste_r
0

We use the Math.random class to generate a number from 1 to 6.
We do this again to generate the second number.
We have a total variable that gets the total of the 2 random numbers.
--------------------------------------------------------------------
public static void main(String[] args) {

//variables to hold numbers for the die and total
int no1 = (int)(Math.random()*6) + 1;
int no2 = (int)(Math.random()*6) + 1;
int total = no1 + no2;

//print out the result
System.out.println("Your first score: " + no1);
System.out.println("Your second score: " + no2);
System.out.println("The total is: " + total);

}
---------------------------------------------------------------------

That should be it, leave feedback! rickste_r!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.