-1

When I write System.out.print(dice) the output is randomly generated number like this:

[3|4|7|6|6]

How Can I use array to have multiple values?

/**
 * This program rolls Yahtzee! dice 1,000,000 times, recording the number of 
 * Yahtzees which occur. After the trials statistics are produced.
 */

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    // TODO code your application logic here
    Scanner input = new Scanner(System.in);
    Random generator = new Random();
    YahtzeeDice dice = new YahtzeeDice(generator);
    System.out.print(dice);
    }
}
Benjamin Hodgson
  • 42,952
  • 15
  • 108
  • 157
  • Check here more or less the same question. http://stackoverflow.com/questions/1067073/initialising-a-multidimensional-array-in-java – Daniel Vieira Mar 24 '15 at 23:57

1 Answers1

0

Not enough reputation to comment. I'm not entirely sure what you require. Does your current code generate those 5 numbers from one run? What is your YahzeeDice class? If you want to record the value of dice to an array you can simple put that in a loop and keep adding dice to an array:

public List<YahtzeeDice> generate(int n) {
    List<YahtzeeDice> results = new ArrayList<YahtzeeDice>();
    YahtzeeDice dice;
    for(int i = 0; i < n; i++) {
        dice = new YahtzeeDice(new Random());
        results.add(dice);
    }
    return results;
}

Something like this? Haven't tested if this compiles. You would then need to call this from your main:

List<YahtzeeDice> diceResults = generate(1000000);
Joao Jesus
  • 186
  • 2
  • 11