title: How to improve code that returns an int array with sorted index, of a given int array?
body: <p>I have made a method that I believe gets an array a, take the three first values in the array and finds the values from low to high. Then those values are put in an new array and send back sorted. This means that with for example:
  int[] a = {9,5,7} returns {1,2,0}. This because a[1] = 5, a[2] = 7 og a[0] = 9.
  int[] a = {1,3,2} should return {0,2,1}. <strong>Array a should not be changed</strong>.</p>
  
  <pre><code>public class Testprogram {
  
  public static void main(String[] args) {
      int[] a = {9,8,7,2,7,8};                          
      System.out.println(Arrays.toString(index(a)));
  
  }
  
  public static int[] index(int[] a)
  {
      int n = a.length;
  
      if (n &lt; 3)
      {
          throw new IllegalArgumentException("array must have at least 3 elements!"); 
      }
  
  
      int min = 0;                    //lowest index
      int nmin = 1;                   //second lowest index
      int tmin = 2;                   //third lowest index
  
      // Controlling that the values in start are in the correct position
      if (a[2] &lt; a[1] &amp;&amp; a[1] &lt; a[0]) 
      { 
          min = 2; 
          nmin = 1; 
          tmin = 0; 
      } 
      else if (a[2] &lt; a[0] &amp;&amp; a[0] &lt; a[1]) 
      { 
          min = 2; 
          nmin = 0; 
          tmin = 1; 
      } 
      else if (a[1] &lt; a[2] &amp;&amp; a[2] &lt; a[0]) 
      { 
          min = 1; 
          nmin = 2; 
          tmin = 0; 
      } else if (a[1] &lt; a[0] &amp;&amp; a[0] &lt; a[2]) 
      { 
          min = 1; 
          nmin = 0; 
          tmin = 2; 
      } 
      else if(a[0] &lt; a[1] &amp;&amp; a[1] &lt; a[2]) 
      { 
          min = 0; 
          nmin = 1; 
          tmin = 2; 
      } else if(a[0] &lt; a[2] &amp;&amp; a[2] &lt; a[1]) 
      { 
          min = 0; 
          nmin = 2; 
          tmin = 1; 
      }
  
      int[] index = new int[] {min, nmin, tmin};
  
      return index;  //returns the array
  }}
  </code></pre>
  
  <p>This method should work with only three comparisons (and max three exchanges (changes?)). </p>
  
  <p>My method with the if(n &lt; 3), has 7 comparisons. 
  Anyone that can help my improve my code?</p>