# Thread: Java program to simulate rolling of two dice (code posted)

1. Member Join Date
Feb 2015
Posts
4
Rep Power
0

## Java program to simulate rolling of two dice (code posted)

Hello! I need help with this problem here. I will post the code below for better understanding.

Write a program to simulate the rolling of two dice. The program should use Math.random (google how to use Math.random if needed) to roll the first die and should use Math.random again to roll the second die. The sum of the two values should then be calculated your program should roll 50,000 times. Use a single dimensional array to tally the numbers of times each possible sum appear(the possible values are 2 through 12, think about why?). Print the results in a tabular format.

Here's the code I'm working on so far:

public class RollingDice{
public static void main(String[] args){
int die1;
int die2;
int roll;

die1 = (int)(Math.random()*6) + 1;
die2 = (int)(Math.random()*6) + 1;
roll = die1 + die2;

System.out.println("The roll of the first dice is: " + die1);
System.out.println("The roll of the second dice is: " + die2);
System.out.println("Your total roll is: " + roll);

}

}

What am I missing at this point, and what parts did I do wrong to change it? Thank you.  Reply With Quote

2. Senior Member Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
15

## Re: Java program to simulate rolling of two dice (code posted)

Do you know how to use loops? Do you know how to use arrays? You have the dice part done. What specifically are you having trouble with?

Regards,
Jim  Reply With Quote

3. Member Join Date
Feb 2015
Posts
4
Rep Power
0

## Re: Java program to simulate rolling of two dice (code posted)

I already have the code figured out. Thank you :)  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•