title: Find 2D array max and min
body: <p>This is the original prompt:</p>
  <blockquote>
  <p>Find the maximum value and minimum value in milesTracker. Assign the maximum value to maxMiles, and the minimum value to minMiles. Sample output for the given program:</p>
  <pre><code>Min miles: -10 
  Max miles: 40
  </code></pre>
  </blockquote>
  <p>Here is my code:</p>
  <pre><code>import java.util.Scanner;
  
  public class ArraysKeyValue {
    public static void main (String [] args) {   
      final int NUM_ROWS = 2;
      final int NUM_COLS = 2;
      int [][] milesTracker = new int[NUM_ROWS][NUM_COLS];
      int i = 0;
      int j = 0;
      int maxMiles = 0; 
      int minMiles = 0; 
  
      milesTracker[0][0] = -10;
      milesTracker[0][1] = 20;
      milesTracker[1][0] = 30;
      milesTracker[1][1] = 40;
  
      for(i=0;i&lt;NUM_ROWS;++i) {
       
         for(j=0;j&lt;NUM_COLS;++j) {
           
            if (milesTracker[i][j]&lt;minMiles){
                minMiles = milesTracker[i][j]; 
            }
            else if (milesTracker[i][j] &gt; maxMiles){
                maxMiles = milesTracker[i][j];
            }
         } 
      }
  
      System.out.println(&quot;Min miles: &quot; + minMiles);
      System.out.println(&quot;Max miles: &quot; + maxMiles);
    }
  }
  </code></pre>
  <p>Here is the output:</p>
  <pre><code>  Testing with milesTracker = {{-10, 20}, {30, 40}}
  </code></pre>
  <p>Your output:</p>
  <pre><code>Min miles: -10
  Max miles: 40
  
     Testing with milesTracker = {{73, 0}}
  </code></pre>
  <p>Your output:</p>
  <pre><code>Min miles: 0
  Max miles: 73
  
  ✖   Testing with milesTracker = {{-5}, {-93}, {-259}}
  </code></pre>
  <p>Expected output:</p>
  <pre><code>Min miles: -259
  Max miles: -5
  </code></pre>
  <p>Your output:</p>
  <pre><code>Min miles: -259
  Max miles: 0
  </code></pre>
  <p>Why is the last test failing?</p>