title: min and max value in 2d array java
body: <p>I want to output max and min value of 2d array. Max works well, but min always outputs zero even when theres no zeros in array.I set <code>Math.random()</code> to 99 to prevent smaller chance to get zero in array for this example. Heres full code:</p>
  
  <pre><code>public class e {
  
  public static void main(String[] args)   {
  
      int a[][] = new int [5][5];
      int l = a[0][0];
      int m = a[0][0];
      int i,j,r,k;
  
  
      for(i=0;i&lt;a.length;i++)                   // 
          for(j=0;j&lt;a[i].length;j++){           // 2d array random number generator
              a[i][j] =(int)(Math.random()*99); //
           }
      for(i=0;i&lt;a.length;i++){               //
          for(j=0;j&lt;a[i].length;j++)         //
                                             // create 2d array and output it
      System.out.print(a[i][j] + "\t");      //   
      System.out.println();                  //
  
  }
      System.out.println("\t"); 
          for(r=0;r&lt;a.length;r++){           //
              for(k=0;k&lt;a.length;k++)        //
                  if(a[r][k] &lt; m){           // finds a min value
                      m = a[r][k];           //
  
              }
          }
  
      System.out.println("\t");               // 
          for(i=0;i&lt;a.length;i++){            //
              for(j=0;j&lt;a.length;j++)         // finds a max value
                  if(a[i][j] &gt; l){            //
                      l = a[i][j];            //
  
              }
          }
      System.out.println("min value is " + m); //outputs min value
      System.out.println("max value is " + l); // outputs max value
              }
         }
  </code></pre>