June 2017
Beginner
1296 pages
69h 23m
English
... indicates the number of grades in the range 0–9, array[7] the number of grades in the range 70–79 and array[10] the number of 100 grades.
1 // Fig. 7.6: BarChart.java
2 // Bar chart printing program.
3
4 public class BarChart {
5 public static void main(String[] args) {
6 int[] array = {0, 0, 0, 0, 0, 0, 1, 2, 4, 2, 1};
7
8 System.out.println("Grade distribution:");
9
10 // for each array element, output a bar of the chart
11 for (int counter = 0; counter < array.length; counter++) {
12 // output bar label ("00-09: ", …, "90-99: ", "100: ")
13 if (counter == 10) {
14 System.out.printf("%5d: ", 100);
15 }
16 else {
17 System.out.printf("%02d-%02d: " ,
18 counter * 10, counter * 10 + 9);
19 }
20
21 // print bar of asterisks
22 for (int stars ...