title: Finding the index of the smallest element in an array (Java)
body: <p>I am trying to write up a block of code that takes an array of integers as an argument and returns the index of the smallest element in the array. Also, the function should return -1 if the list is an empty list.</p>
  
  <p><a href="https://i.stack.imgur.com/hyEMf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hyEMf.jpg" alt="Test for the block of code."></a></p>
  
  <p>So far I have got,</p>
  
  <pre><code>public static int indexOfSmallest(int[] array){
      int index = 0;
      int min = array[index];
  
      for (int i = 1; i &lt; array.length; i++){
          if (array[i] &lt;= min){
          min = array[i];
          index = i;
          }
      }
          return index;
  }
  </code></pre>
  
  <p>But, I'm getting this error and unsure what I need to fix.</p>
  
  <p><a href="https://i.stack.imgur.com/QDYZc.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QDYZc.jpg" alt="enter image description here"></a></p>
  
  <p>Any help would be much appreciated. Thank you.</p>