title: Counting number of occurrence in randomly generated numbers
body: <p>I have a Java program that generates 100 random integers between 0 and 9 and I need to make it display the count for each number. the example of that is this:</p>
  
  <pre><code>*************************************************************************
  Generating 100 random integers between 0 and 9
  Number 1 = 3
  Number 2 = 0
  … (your program must display all generated numbers)
  Number 100 = 8
  *************************************************************************
  0 occurs 1 time
  1 occurs 9 times
  2 occurs 18 times
  3 occurs 20 times
  4 occurs 5 times
  5 occurs 20 times
  6 occurs 1 time
  7 occurs 1 time
  8 occurs 25 times
  9 occurs 0 time
  *************************************************************************
  </code></pre>
  
  <p>So far I have this much:</p>
  
  <pre><code> import java.util.Random;
      public class World {
      public static void main(String[] args) {
  
          public void generateNumber(){
  System.out.println("*************************************************************************");
             System.out.println("Generating 100 random integers between 0 and 9");
  
          Random aGenerator = new Random();
  
          int randomArray[]=new int[101];
          int countArray[]=new int[10];
  
          //generate the numbers and store into an array
          int j;
          for(int i=1; i&lt;101; ++i) {
              j=i;
                  randomArray[i]=aGenerator.nextInt(10);
  
                  //displaying numbers
                    System.out.println("Number " + j + " = " + randomArray[i]);
  
              }
  
  
  
   System.out.println("*************************************************************************");
  
  //counting the numbers
  for(int i=1;i&lt;100;i++){
      countArray[randomArray[i]-1] = countArray[randomArray[i]-1]+1;
  
  //displaying the counts
      j=i;
      System.out.println(randomArray[i]+" occurs "+countArray[i]+ " times");
  
      }
  
  
  
  
             }
  }
  }
  </code></pre>
  
  <p>and the generating and displaying random numbers work fine, however, the counting part looks like this </p>
  
  <pre><code>*************************************************************************
  5 occurs 0 times
  7 occurs 0 times
  7 occurs 0 times
  9 occurs 1 times
  2 occurs 0 times
  2 occurs 2 times
  1 occurs 0 times
  4 occurs 1 times
      at Generator.generateNumber(2 appears 0 times
  Generator.java:33)
      at World.main(World.java:17)
  </code></pre>
  
  <p>Please help me by telling which part I did wrong? Thank you so much for your time!</p>