title: Switching the smallest and largest value in an object array in Java
body: <p>I'm instructed to swap the largest and smallest value in an object array in Java. I wrote my code and it seems reasonable, but for some reason the values aren't switching??? I'm not quite sure what's wrong with my code, can someone point me in the right direction? Thank you!!</p>
  
  <p><strong>This is my code:</strong></p>
  
  <pre><code>public class Measurables
  {
     /**
        Swaps the values with the smallest and largest measure.
        @param objects an array of objects of a class that implements the
        Measurable interface.
     */
     public static void swapMinAndMax(Measurable[] objects)
     {
  
        Measurable largest = objects[0]; 
        Measurable smallest = largest;
        for (int i = 1 ; i &lt; objects.length ; i++)
        {
           Measurable current = objects[i];
           if ( largest.getMeasure() &lt; current.getMeasure())
           {
              largest = current;
           }
           if (smallest.getMeasure() &lt; current.getMeasure())
           {
              smallest = current;
           }
           Measurable temp = largest; 
           largest = smallest;
           smallest = temp;
  
           }
        }
  }
  </code></pre>
  
  <p><strong>This is what I get when I run the tester:</strong></p>
  
  <pre><code>Testers
  
  Running Tester.java
  
  fail
  [Uruguay, Thailand, Belgium]
  Expected: [Uruguay, Belgium, Thailand]
  Running Tester2.java
  
  fail
  [BankAccount[balance=1000.0], BankAccount[balance=3000.0], BankAccount[balance=2000.0]]
  Expected: [BankAccount[balance=3000.0], BankAccount[balance=1000.0], BankAccount[balance=2000.0]]
  Running Tester3.java
  
  pass
  [Uruguay]
  Expected: [Uruguay]
  </code></pre>