Sarah Love
Netbeans Question need help desperately!!
0 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners

Ok here is my code-

public class RollDie2 {


public static void main(String[] args) {

    Random randomNumber = new Random();

int[][] frequency = new int[9][9];
int die1 = 0;
int die2 = 0;


for (int roll = 1; roll <= 64000; roll++) {
die1 = randomNumber.nextInt(8) + 1;
die2 = randomNumber.nextInt(8) + 1;
frequency[die1][die2] = frequency[die1][die2] + 1;
frequency[die2][die1] = frequency[die2][die1] + 1;
}
System.out.printf("%5s%10s%15s\n", " Number", "Number", " Frequency");
for (int number = 0; number <= 16; number++) {
System.out.printf("%4d%10d\n", number, number, number, frequency[die1][die2] + 1);

okay that's the code....I'm trying to get a two-dimensional array to tally the actual combinations of rolls on 8 sided dice. How do I get the frequency of the numbers to print?

Advertisement
View Answers









Related Tutorials/Questions & Answers: