// Question 6.24, page 246
// Read in integers between -25 and 25 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 -25 to 25 is entered.

import java.io.*;
public class q24 {

   // 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
      final int OFFSET = 25;           // offset from index zero

      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 -25 and 25.");
      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-OFFSET) && value <= (MAXINT-OFFSET)) {
         list[value+OFFSET] = list[value+OFFSET] + 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-OFFSET +": "+list[i]);
      }
   }
}

