Can anyone explain the output of this code? I have been hitting my head really hard to understand, but I just don't get it.
public static void main(String ars[]) {
int responses[] = {1,2,4,4};
int freq[] = new int[5];
for(int answer = 1; answer < responses.length; answer++) {
++freq[responses[answer]];
}
for (int rating = 1; rating < freq.length; rating++)
System.out.printf("%6d%10d\n", rating, freq[rating]);
}
Output
1 0
2 1
3 0
4 2