I am trying to make a program that lets the user choose how many times he want to throw the dice, and then every value of the thrown dice should be counted. In the end of the program the user should see how many times he threw 1, 2, 3 etc. This is a program to see if every number has an equal chance of being shown.
I encountered problems in the beginning of my code since I don't know how to let the computer throw the dice lets say 1000 times and then save every value from those thrown dices. This is what I have so far:
import java.util.Scanner;
public class Uppgift4_5
{
public static void main(String[] args)
{
Scanner inputReader = new Scanner (System.in);
System.out.println("How many times do you want to throw the dice:");
int amount = inputReader.nextInt();
int [] dice = { 1, 2, 3, 4, 5, 6 };
int random = 0;
for (int i = 0; i < amount; i++)
{
random = (int) (Math.random () + 1);
}
}
}
The problem I'm facing is that it only saves one random number and then loops that number 6 times. As you can see I have not come far, I just need to know how I can save and count every individual thrown dice. And then I think I am going to use a switch and case to somehow save that(any suggestions there would also be helpful). Any suggestions or answers would be helpful. Thanks.
Aucun commentaire:
Enregistrer un commentaire