HW6.3

HW6.3

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter the integers between 1 and 100: ");
10 
11         int number;
12         int[] storage = new int[101];
13 
14         while(true)
15         {
16             number = input.nextInt();
17             if(number == 0)
18                 break;
19             storage[number]++;
20         }
21 
22         input.close();
23 
24         for(int i = 1; i < 101; i++)
25         {
26             if(storage[i] == 1)
27                 System.out.println(i + " occurs 1 time");
28             else if(storage[i] > 1)
29                 System.out.println(i + " occurs " + storage[i] + " times");
30         }
31     }
32 }