I am practicing using The new Boston tutorials, however there is one program that I don't fully understand. The program is designed to count the frequency of a number occuring in each dice roll and storing the results in an array. The line I have trouble with is ++freq[1+newDice.nextInt(6)]. I understand [1+newDice.nextInt(6)]; however how does the array know to increment each index by one each time the number occurs?
Random newDice = new Random ();
int freq[] = new int [7];
for(int i = 1; i<= 1000; i++)
{
++freq[1+newDice.nextInt(6)];
}
System.out.println("Dice Number\tFrequency");
for(int i = 1; i< freq.length; i++)
{
System.out.println(i+"\t\t"+freq[i]);
}