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 2 of 2

Thread: I'm trying to output my results in a table. Can you help?

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Thanked 0 Times in 0 Posts

    Default I'm trying to output my results in a table. Can you help?

    The code I have below asks the user how many times you want to roll the dice. It rolls dice 1 and dice 2 randomly and gives the total. My programming is all good to this point.

    Now, I'm trying to keep track of the result of each roll using an array that is indexed by the sum of the roll of the two dice. Then I want to output my result in a table that shows each value (from 2 - 12)) and the number of times that value was rolled. I would like to do this preferably with the JTextArea class, but it doesn't have to be. I keep getting errors. Can anyone help? The code below works for the dice rolling in the 1st paragraph. I took out all the bad code I was trying to use for the 2nd paragraph.

    package Part2pack;

    import java.util.Random;

    import javax.swing.JOptionPane;

    class Dice{

    public static void main (String args[])


    String input = " ";

    int count = 0,dice1,dice2;

    input = JOptionPane.showInputDialog(null, " Enter how many times the dice should be rolled: ");

    count = Integer.parseInt(input);

    Random random = new Random();

    for (int num = 1; num <= count; ++num)



    dice1=getRandomInteger(1, 6, random);

    dice2=getRandomInteger(1, 6, random);

    System.out.println("1st dice");
    System.out.println("2nd Dice");



    private static int getRandomInteger(int begin, int finish, Random random)

    long range = (long)finish - (long)begin + 1;

    long fraction = (long)(range * random.nextDouble());

    int randomNumber = (int)(fraction + begin);

    return randomNumber;



  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: I'm trying to output my results in a table. Can you help?

    Please read Announcements - What's Wrong With My Code? for forum guidelines, including how to properly format your code.

    I keep getting errors.
    What errors? Post them in their entirety.

Similar Threads

  1. Replies: 0
    Last Post: March 1st, 2013, 08:13 PM
  2. how could I output to a text area the output of a method
    By mia_tech in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 12th, 2012, 07:49 PM
  3. need help with validating results
    By tim1234 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 13th, 2011, 10:50 AM
  4. How to Accumulate results
    By DreamNaut in forum Java Theory & Questions
    Replies: 2
    Last Post: October 29th, 2010, 01:10 AM
  5. Football Results
    By RSYR in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 4th, 2009, 07:24 PM