40 students were asked about the quality of food in the student canteen, on a scale of 0 to 10. (1 meaning awful and 10 mean excellent). Put the forty responses into an entire array and summarize the search results.
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int tamanhoResposta = 40, frequencySize = 11;
int response[] = {5, 10, 6, 7, 3, 7,5 ,6 ,3, 10, 4,5,4,9,8,7,5,6,5,6,4,5,6,7,8,4,3,8,9,10,9,6,5,3,9,5,9,10};
int frequency[] ={0};
for(int i = 0; i < tamanhoResposta; i++){
++frequency[response[i]];
}
System.out.println(" Avaliação ===================== Frequência " );
for(int ii = 0; ii < frequencySize; ii++){
System.out.println(ii + " ");
System.out.println(frequency[ii]);
}
I do not understand what this part is for, but what does it do?
++frequency[response[i]];
It gives this exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5