- What is the purpose of all those loops?
- If a given number (for example, 8) is never rolled, how many rolls will your code think it was rolled?
- Again--what is the purpose of curly brackets (the "{}" characters) in
Java?
As reference point, the code to solve this problem is an order of magnitude shorter than you're currently making it. It's often helpful to think about the overall nature of the problem--here's one way I might think about it:
- I'm rolling a die
n times, which sounds a lot like a
for-loop.
- For each roll I record which number was rolled (you're using distinct variables, someone else suggested an array, which would eliminate quite a bit of code).
- After I've rolled the die an appropriate number of times I do the calculations (which you're doing correctly, more or less, although there seems to be a spurious semi-colon in your
counter1 code).