Using Arrays to Analyze Survey Results
Our next example uses arrays to summarize data collected in a survey. Consider the following problem statement:
Twenty students were asked to rate on a scale of 1 to 5 the quality of the food in the student cafeteria, with 1 being “awful” and 5 being “excellent.” Place the 20 responses in an integer array and determine the frequency of each rating.
This is a typical array-processing application (Fig. E.7). We wish to summarize the number of responses of each type (that is, 1–5). Array responses
(lines 9–10) is a 20-element integer array containing the students’ survey responses. The last value in the array is intentionally an incorrect response (14
). When a Java program executes, array element indices are ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.