244 Arrays Chapter 7 6 7 class Histogram (Frontpage web hosting)
244 Arrays Chapter 7 6 7 class Histogram 8 { 9 // main entry point for application 10 static void Main( string[] args ) 11 { 12 int[] n = { 19,3,15, 7, 11, 9, 13, 5,17,1 }; 13 string output = “”; 14 15 output += “ElementtvaluetHistogramn”; 16 17 // build output 18 for ( int i = 0; i < n.Length; i++ ) 19 { 20 output += "n" + i + "t" + n[ i ] + "t"; 21 22 for ( int j = 1; j <= n[ i ]; j++ ) // print a bar 23 output += "*"; 24 } 25 26 MessageBox.Show( output, "Histogram Printing Program", 27 MessageBoxButtons.OK, MessageBoxIcon.Information ); 28 29 } // end Main 30 31 } // end class Histogram Fig. 7.5 Program that prints histograms. (Part 2 of 2.) 7.4.4 Using the Elements of an Array as Counters Sometimes programs use a series of counter variables to summarize data, such as the results of a survey. In Chapter 6, Methods, we used a series of counters in our dice-rolling program to track the number of occurrences of each side on a six-sided die as the program rolled 12 dice at a time. We also indicated that there is a more elegant method than that in Fig. 6.11 for writing the dice-rolling program. An array version of this application is shown in Fig. 7.6. The program uses the seven-element array frequency to count the occurrences of each side of the die. Line 94, which uses the random facevalue as the subscript for array fre
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.