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());
		}
}

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.

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

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

Edited 5 Years Ago by WolfShield: n/a

This article has been dead for over six months. Start a new discussion instead.