title: Why am I getting an error for index 0 out of bounds for length 0 when trying to print separate rows of stars?
body: <p>I expected it to print the stars. The results were that it printed the stars in the way I wanted, but I got an error when testing saying, &quot;ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0&quot;.
  Code:</p>
  <pre><code>public class Printer {
  
      public static void main(String[] args) {
          // You can test the method here
          int[] array = {5, 1, 3, 4, 2};
          printArrayInStars(array);
     }
  
      public static void printArrayInStars(int[] array) {
          // Write some code in here
     
           int i = 1;
          while (i&lt;=array[0]) {
              System.out.print(&quot;*&quot;);
              i++;           
          }
          System.out.println(&quot;&quot;);
      
          int a = 1;
          while (a&lt;=array[1]) {
              System.out.print(&quot;*&quot;);
              a++;           
          }
          System.out.println(&quot;&quot;);
      
          int b = 1;
          while (b&lt;=array[2]) {
              System.out.print(&quot;*&quot;);
              b++;           
          }
          System.out.println(&quot;&quot;);
      
          int c = 1;
          while (c&lt;=array[3]) {
              System.out.print(&quot;*&quot;);
              c++;           
          }
          System.out.println(&quot;&quot;);
  
          int d = 1;
          while (d&lt;=array[4]) {
              System.out.print(&quot;*&quot;);
              d++;           
          }
          System.out.println(&quot;&quot;);
      }
  }
  </code></pre>
  <p>Results:</p>
  <hr />
  <ul>
  <li></li>
  </ul>
  <hr />
  <hr />
  <p>**</p>