import java.util.Scanner;

/**
 * Program reads integers between 1 and 10 and counts the occurrences of each.
 * Assume input ends with 0.
 */
public class CountOccurrences {
	public static void main(String[] args) {
		// Prompt user for input
		System.out.println("Enter integers [1,10]; enter 0 to stop:");
		
		// Read input from the keyboard
		Scanner in = new Scanner(System.in);
		
		// Create array to store counts
		int[] counts = new int[10];
		
		/*
		 * Version we built in class
		 */
		
		// Sentinel value for while loop
		boolean doneReading = false;
		
		// Continue reading input until sentinel changes
		while (!doneReading) {
			// Read the next integer value
			int num = in.nextInt();
			
			// One option: use a switch statement
			// switch(num) {
				// case 1: ...
			//}
			
			// Stop if we find 0
			if (num == 0) {
				doneReading = true;
			} 
			// Otherwise, increment the appropriate counter
			else {
				counts[num-1]++;
			}		
		}
		
		
		/*
		 * Alternate option
		 */
		
		// Variable to store the numbers we read from the user
		int num;
		do {
			// Read the next integer value
			num = in.nextInt();
			// As long as != 0, increment the appropriate counter
			if (num != 0) {
				counts[num-1]++;
			}
			
		} while (num != 0);
		
		
		// Output what we've seen
		for (int i = 0; i < counts.length; i++) {
			System.out.print((i+1) + " appeared " + counts[i] + " time");
			if (counts[i] != 1) {
				System.out.print("s");
			}
			System.out.println();
		}
		
		// Close scanner to avoid resource leak
		in.close();
	}
}
