title: How do I create a counter for each element in an array?
body: <p>So I have to write a program that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered.  Indicate the end of the input by a value outside of the range. After  all input  has  been  processed.,  print all of the values (with  the number  of occurrences)  that were entered  one or more time.</p>
  
  <pre><code>public class problem
  {
      public static void main(String[] args) 
      {
          Random rand = new Random(); 
          Scanner scan = new Scanner(System.in);
  
          int userInput = 0;
          ArrayList&lt;Integer&gt; myList = new ArrayList&lt;Integer&gt;();
          int index = -1;
  
          for (int num = 0; num &lt;= userInput ; num++)
          {   
              System.out.println("Please enter a random number between 0 and 50, enter a negative number to end input: ");
              num--;
  
              if(userInput &gt;= 0 || userInput &lt;= 50)
              {       
                  userInput++;
                  userInput = scan.nextInt();
                  index++;
                  myList.add(userInput);
              }
              if (userInput &lt; 0 || userInput &gt; 50)
              {
                  myList.remove(index);
                  index--;
                  break;
              }
          }   
  
          for (int num: myList)
              System.out.print(num + " ");
  
      }
  }
  </code></pre>
  
  <p>This is what I have so far, but I am stuck as to how to count each integer occurrence in myList.</p>