// Question 6.23, page 246
// Read in integers between 0 and 50 and report how many
// of each number there were.
//
// Assumption: program stops reading numbers when an integer value
//            that is not in the range of 0 to 50 is entered.

import java.io.*;
public class q23 {

   // Main method to read the integers, store counts for each in an
   // array, and to report how many of each number there was.
   public static void main(java.lang.String[] args) throws IOException {

      DataInputStream stdin = new DataInputStream (System.in);
      final int MAXINT = 50;           // Largest integer considered
      final int MININT = 0;            // Smallest integer considered

      int[] list = new int[MAXINT+1];  // Array has counters for each int

      // Initialize all locations in the array to zero
      for (int i=0; i<list.length; i++) {
         list[i] = 0;
      }

      // Prompt user to enter a list of integers
      System.out.println ("Enter a list of integers between 0 and 50.");
      System.out.println ("To stop, enter an integer not in this range.");

      // Enter first integer value before loop
      System.out.print ("Enter Integer: ");
      int value = Integer.parseInt (stdin.readLine());

      // As long as the integers entered are within the desired range,
      // keep entering integers and increasing the appropriate index
      // in the 'list' array.
      while (value >= MININT && value <= MAXINT) {
         list[value] = list[value] + 1;

         // Enter next integer value
         System.out.print ("Enter Integer: ");
         value = Integer.parseInt (stdin.readLine());
      }

      // Print the summary.
      System.out.println ("\nHere are how many of each value was entered:");
      for (int i=0; i<list.length; i++) {
         if (list[i] > 0)
            System.out.println (i+": "+list[i]);
      }
   }
}

