Hello Everybody. This code is suppose to add ask the user how many dice they would like to roll, and how many times to roll them. Eventually I will need to use an array to store the roll numbers, so I can print out how many times each number turned up. But right now, I'm just trying to get the rolls to work. However, the total of the rolls is turning up as one number instead of the amount the user enters. Any help would be appreciated.
CODE
import java.util.*;
public class Dice2 {
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, roll);
System.out.println (dicetotal);
}
public static int Dicecount (int dice, int roll) {
int dicetotal = 0;
for (int i = 0; i <roll; i++) {
for (int x = 0; x < dice; x++) {
int rollcount =(int)(1+6*(Math.random()));
dicetotal+=rollcount; }
return dicetotal;
}
}