I have difficulty in understanding some line of code in this roll die JAVA program using arrays. This program notes the frequency of the numbers 1-6 and then displays in console.
import java.security.SecureRandom;
public class RollDie{
public static void main(String[] args){
SecureRandom randomNumbers=new SecureRandom();
int[] frequency=new int[7]; //array of frequency counter
//roll die 6000000 times, use die value as frequency index
for(int i=1; i<=6000000;i++)
++frequency[1+randomNumbers.nextInt(6)];
System.out.printf("%s%10s%n","face","frequency");
for(int face=1;face<frequency.length;face++)
System.out.printf("%4d%10d%n", face, frequency[face]);
}
}
can anyone explain this line:
++frequency[1+randomNumbers.nextInt(6)];