You have two dice, and the result of a die roll can be from 0 to 5. I assume the 1001 means you want to roll the two dice 1001 times. Please let me know if I missed anything here.
In this case your min roll would be a 0, and max 10. But, adding 1 to both dice rolls before accessing would mean your index goes from 2 to 12 which causes your ArrayIndexOutOfBoundsException
.
Just don't add anything to the roll. Remember java arrays start from 0, so a range of 0 to 10 is fine.
Quick example:
public static class Die {
static Random rand = new Random();
public static int nextInt(int val) {
return rand.nextInt(val);
}
}
public static void main(String[] args) {
int[] counters = new int [11];
for (int i = 0; i <1001; i++){
//no need to add anything
++counters[Die.nextInt(6) + Die.nextInt(6)];
}
System.out.print(Arrays.toString(counters));
}
Example output:
[27, 60, 81, 106, 157, 175, 120, 109, 81, 55, 30]
Which we can translate to mean that a "2" was rolled 27 times, "3" 60 times, etc.