Hello Everybody. I am trying to write a program that asks the user to enter the amount of dice they want to use, and how many rolls they would like to make. Eventually I will need to store the output in strings, so I can print out how many times each number showed up (ex. 7 Showed up 2 Times). However, Right now I am just trying to print out the value of the rolls. I am trying to figure out how to have the dice values add up (and return that) and repeat the loop for how many rolls the person enters. This is what I have so far, it is currently adding up all rolls and printing out one value.

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, 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;



Recommended Answers

All 2 Replies

So if you want to show the value of the rolls individually, you will want something like:


I'll let you figure out where to put it, but it shouldn't be too hard.

I need to add all the values of the dice together, before printing them. Is there anyway to do this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.