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
...

>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

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.

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.