title: java - largest to smallest sort - largest is out of order
body: <p>I'm trying to get this sorting algorithm to sort largest to smallest in an array. Here's what I have:</p>
  
  <pre><code>private void sort(int[] data) {
      int min;
      for (int index = 0; index &lt; data.length - 1; index++) {
          min = index;
          for (int scan = index + 1; scan &lt; data.length; scan++) {
              if (data[scan] &gt; data[min]) min = scan;
              swap (data, min, index);
          }
      }
  }
  
  private void swap(int[] data, int pos0, int pos1) {
      int temp = data[pos0];
      data[pos0] = data[pos1];
      data[pos1] = temp;
  }
  </code></pre>
  
  <p>the output is:</p>
  
  <pre><code>3 3 4 2 2 2 2 1 1 1 1 1 1
  </code></pre>
  
  <p>why is the second largest number out of order?</p>
  
  <p>I keep going through this and I'm clearly missing something.</p>