Array as Counters in Java, can anyone help me understand the program below.
class RollaDice{ public static void main (String[] args){ Random Rand = new Random(); it freq[] = new int[7]; for (int roll=1;roll<100;roll++){ ++freq[1+rand.nextInt(6); } System.out.println("Face\tFrequency"); for (int face=1;face<freq.length;face++){ System.out.println(face+"\t"+freq[face]); } } } RollaDice will roll between 1-6 and the above program displays the number of times an index is visited with a particular value in it. The value randomly generated between 1 to 6 using the utility called Random. That is the theoretical part but I am finding it hard to understand the actual logic. Any one with the explanation ? I have been following the Buckys java tutorial and if you want more info on this, take a look https://www.youtube.com/watch?v=pHxtKDENDdE&list=PL484D73FA74A11AC9&index=30