Hello Everybody. This program needs to use an array to count the amount of times a certain roll appears on the dice, after the user enters how many dice and rolls they would like to use. I was able to figure out the code to print out the values of each roll, however I'm not sure what I would have to do to use an array as a counter. Any help would be appreciated.
Example Results:
You Rolled 2: 1 Time
You Rolled 3: 0 Times
You Rolled 4: 3 Times
etc.
Here is my code so far:
import java.util.*;
public class Dice {
public static Scanner in = new Scanner (System.in);
public static void main (String[] args) {
int dice = 0;
int roll = 0;
while (true) {
System.out.print ("How Many Dice Do You Want To Roll? ");
dice = in.nextInt();
if (dice > 0) break;
System.out.println ("Must Be Positive!");
}
while (true) {
System.out.print ("How Many Times Do You Want To Roll? ");
roll = in.nextInt();
if (roll > 0) break;
System.out.println ("Must Be Positive!");
}
int dicetotal = Dicecount (dice);
for (int i = 0; i < roll; i++) {
System.out.println (Dicecount(dice));
}
}
public static int Dicecount (int dice) {
int dicetotal = 0;
for (int x = 0; x < dice; x++) {
int rollcount =(int)(1+6*(Math.random()));
dicetotal+=rollcount; }
return dicetotal;
}
}