title: Using Random Class to populate array and then print it's values
body: <p>I'm relatively new to programming in Java.</p>
  
  <p>I've got a task for class in which I have to populate an array with random numbers from 0 to 100. However the user needs to be able to define the number of random numbers which are inserted within this array. For this I've created the variable 'n' for now.</p>
  
  <p>I think I've got most of the code nailed. I wanted to experiment using the Random class to create the random numbers, as opposed to math.random*100. </p>
  
  <p>I'm getting an error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
    10    at CreateArray.main(CreateArray.java:11)</p>
  </blockquote>
  
  <p>Here's my code:</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.Random;
  
  public class CreateArray{
      public static void main(String [] args){ 
          int n = 10;
          Random myrandom = new Random(); 
          int[] engine = new int[n]; // Initialising my array and giving it the name engine, I'm also passing value 'n' to my array length
          engine[n] = myrandom.nextInt(100-0); //This exclues 100 and 0, to include those I would say +100 or +0
  
          for(int i=0; i &lt; engine.length; i++){ //Using a for loop to cycle through my array and print out its elements
              System.out.println(engine[i]); //Printing out my array 
          }
      }
  }
  </code></pre>