954,523 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help Dice simulator

hi,
im trying to create a program that records the amount of times a number was rolled using input from the user. currently it is only printing 1 number and i need it to print 6. i am only beginning to study java so im lacking knowledge a bit. any help would be appreciated. i am expected to use Math.random() so no "import java.util.Random;" here is my code:

class DiceRandom
{
	static int random()
	{
		int die1 = (int)(Math.random()*6) + 1;
 		return die1;
 	}

	public static void main(String[] args)
	{
		System.out.println("How many times do you want to roll the dice?");
			int input = Console.readInt();
			System.out.println("you rolled the dice "+input+" times.");

			int [] mark = {random()};

			int count = input;
			for(int i = 0; i < mark.length; i++)
				while(mark[i] >= 6)
					count++;
			System.out.println(count*random());
		}
}
thechicken
Newbie Poster
1 post since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Do you have any specific questions about your code?
If you are getting errors, please copy and paste them here.
If the output is wrong, show the output and explain what is wrong with it.

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

You should output the results to an array diceroll[i] and at the end you can see how many times each number was rolled

epbyrne
Newbie Poster
1 post since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

If I understand your problem correctly, t is only printing one (1) number when it should be printing the number inputted ( in this case: 6). What I see is that your last line is not in the for loop. So you are only asking it to print ONCE. Try putting your last line of posted code in the for loop.

- WolfShield

WolfShield
Posting Whiz in Training
236 posts since Oct 2010
Reputation Points: 28
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: