Results 1 to 3 of 3
  1. #1
    theefancyone is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

    Default 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.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default 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
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    theefancyone is offline Member
    Join Date
    Feb 2015
    Posts
    4
    Rep Power
    0

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

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

Similar Threads

  1. Can't get java dice program to work
    By name in forum New To Java
    Replies: 2
    Last Post: 11-24-2011, 05:53 PM
  2. Replies: 4
    Last Post: 01-04-2011, 12:36 AM
  3. Please help..dice java program
    By aronkevin in forum New To Java
    Replies: 3
    Last Post: 10-08-2010, 05:37 AM
  4. Java rolling dice
    By fifa4ever in forum Java Applets
    Replies: 18
    Last Post: 06-10-2010, 08:43 PM
  5. Java Program (rolling the dice)
    By genocist in forum New To Java
    Replies: 8
    Last Post: 03-01-2010, 03:15 PM

Posting Permissions

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