@@ -66,35 +66,6 @@ public static void main(String[] args) {
6666 makeHistogram ();
6767 }
6868
69- /**
70- * Example code related to histograms.
71- */
72- public static void makeHistogram () {
73- int numValues = 8 ;
74- int [] array = randomArray (numValues );
75- printArray (array );
76-
77- int [] scores = randomArray (30 );
78- int a = inRange (scores , 90 , 100 );
79- int b = inRange (scores , 80 , 90 );
80- int c = inRange (scores , 70 , 80 );
81- int d = inRange (scores , 60 , 70 );
82- int f = inRange (scores , 0 , 60 );
83-
84- // making a histogram
85- int [] counts = new int [100 ];
86- for (int i = 0 ; i < scores .length ; i ++) {
87- int index = scores [i ];
88- counts [index ]++;
89- }
90-
91- // histogram with enhanced for loop
92- counts = new int [100 ];
93- for (int score : scores ) {
94- counts [score ]++;
95- }
96- }
97-
9869 /**
9970 * Prints the elements of an array.
10071 */
@@ -153,4 +124,33 @@ public static int inRange(int[] a, int low, int high) {
153124 }
154125 return count ;
155126 }
127+
128+ /**
129+ * Example code related to histograms.
130+ */
131+ public static void makeHistogram () {
132+ int numValues = 8 ;
133+ int [] array = randomArray (numValues );
134+ printArray (array );
135+
136+ int [] scores = randomArray (30 );
137+ int a = inRange (scores , 90 , 100 );
138+ int b = inRange (scores , 80 , 90 );
139+ int c = inRange (scores , 70 , 80 );
140+ int d = inRange (scores , 60 , 70 );
141+ int f = inRange (scores , 0 , 60 );
142+
143+ // making a histogram
144+ int [] counts = new int [100 ];
145+ for (int i = 0 ; i < scores .length ; i ++) {
146+ int index = scores [i ];
147+ counts [index ]++;
148+ }
149+
150+ // histogram with enhanced for loop
151+ counts = new int [100 ];
152+ for (int score : scores ) {
153+ counts [score ]++;
154+ }
155+ }
156156}
0 commit comments