Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: help with coding dice game

  1. #1
    Junior Member
    Join Date
    Apr 2018
    Thanked 0 Times in 0 Posts

    Question help with coding dice game

    Good evening, I am trying to code a rolling dice game. As of right now, I am just trying to figure out how to roll two dice randomly at a time. Here is my code so far

    I am not sure how to return the sum of the two dice, or if I am even supposed to do it that way. Any help would be appreciated!

    import java.util.Random;
    public class TwentyOne{

    public static void main(String[] args) {

    int dice1;
    int dice2;

    rollingDice(int dice1,int dice2);


    public static void welcome() {
    System.out.println("Welcome to the game of Twenty-One! FEELING LUCKY?! goodluck!");


    public static int rollingDice(int dice1, int dice2) {

    dice1 = (int)(Math.random()*6 + 1);
    dice2 = (int)(Math.random()*6 + 1);
    int sum = dice1 + dice2;
    return sum;



  2. #2
    Member John Joe's Avatar
    Join Date
    Jun 2017
    My Mood
    Thanked 18 Times in 18 Posts

    Default Re: help with coding dice game

    You need to assign a variable to get the return value
    int sum = rollingDice(int dice1,int dice2);
    Whatever you are, be a good one

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,461 Times in 2,412 Posts

    Default Re: help with coding dice game

    Have you tried to compile the code? What error messages do you get?
    Please copy the full text and paste it here.

    When posting code be sure to wrap your code with code tags:


    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Dice Game! PLEASE HELP!
    By mhaxton in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 14th, 2013, 12:47 PM
  2. Replies: 3
    Last Post: March 1st, 2013, 11:01 PM
  3. [SOLVED] Dice game need help
    By lf2killer in forum Loops & Control Statements
    Replies: 6
    Last Post: October 5th, 2012, 02:25 AM
  4. Need help coding Dice rolling simulation
    By DavidBowie in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 23rd, 2011, 02:03 PM
  5. Dice Game help and Arrays
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 9th, 2011, 10:08 PM

Tags for this Thread