title: Java find min and max value in 2d array. Minimum value found is not correct
body: <p>Here is my code in which I declare a 2d array with all the values and I'm trying get it to print the min and max values. The max value turns out right but the min value does not. When I run it, the max is 9.73 (which is correct) and the min printed is 5.44, which is incorrect because if you look at the values in the array, you see that 5.29 is the minimum value. Does anyone know why it won't find the correct min value? Thanks in advance!</p>
  
  <pre><code>public class Test {
    public static double[][] array1 = //array to be used
     {{7.51, 9.57, 6.28, 5.29, 8.7},
      {8.07, 6.54, 5.44, 8.78, 8.66},
      {9.34, 9.73, 7.19, 6.87, 6.48}};
    public static void main(String[] args) {
      double h = array1[0][0];// highest value
      double l = array1[0][0];// lowest value 
      for (int row = 1; row &lt; array1.length; row++){ //find highest value
        for (int col = 1; col &lt; array1.length; col++){
          if (array1[row][col] &gt; h){
           h = array1[row][col]; 
          }
        }
      }
      for (int r = 1; r &lt; array1.length; r++){ //find lowest value
        for (int c = 1; c &lt; array1.length; c++){
          if (array1[r][c] &lt; l){
           l = array1[r][c]; 
          }
        }
      }
      System.out.println(h);//print highest
      System.out.println(l);//print lowest
    }
  }
  </code></pre>