0

Write a program which uses a for statement to simulate 120000 rolls of two dice. 'Keep track' of the number of times each possible outcome (a total in the range 2 to 12) is rolled using 11 integer variables. After all the rolls output a table showing the number of times each possible outcome occurred. For example

Total Number of times rolled
--------------------------------
2 3451
3 6795
...

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by BestJewSinceJC
0

>Create variables to hold how many times each value occured:

int countOf2s = 0;
int countOf3s = 0;
...

>Create a method that returns a random number from 1 to 6
> inside a for loop (it will be executed 12000) call the above methods 2 times, add their results and depending on the outcome increase by 1 the appropriate variable
> the loop will be repeated and in the end will have the number of occurences stored at the variables
> print those variables

0

Do what JavaAddict suggested, I would suggest one minor modification though: use an integer array of size 12 (one for each value) to keep track of the number of times each has occurred. Simply increment the index- increment index 0 if you see a 1, index 1 if you see a 2, and so on.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.