title: error trying to find a saddle point in a matrix
body: <p>I have written some code to find the position of a saddle point (an element within a matrix which is the maximum element of its corresponding row and simultaneously the minimum of its column) of a matrix. However, there is an error saying:</p>
  
  <pre><code>The local variable col may not have been initialized
  at SaddlePoint.findSaddle(SaddlePoint.java:41)
  at SaddlePoint.main(SaddlePoint.java:52)
  </code></pre>
  
  <p>I can't understand why it is saying so.  Any help would be very much appreciated.  Below I have given my code:</p>
  
  <pre><code>public class SaddlePoint {
  
      int arr[][]=new int[4][5];
  
      public SaddlePoint(int x[][])
      {
          for(int i=0;i&lt;arr.length;i++)
              for(int j=0;j&lt;arr[i].length;j++)
                  arr[i][j]=x[i][j];
      }
  
      public void display(int x[][])
      {
          System.out.println();
          for(int i=0;i&lt;arr.length;i++)
          {for(int j=0;j&lt;arr[i].length;j++)
              System.out.print(arr[i][j]+"\t");
              System.out.println();
          }
      }
      public void findSaddle()
      {
          int row,col,flag;
          for(int i=0;i&lt;arr.length;i++)
          {int max=arr[i][0];col=0;flag=0;
              for(int j=1;j&lt;arr[i].length;j++)
                  if(max&lt;arr[i][j])
                  {max=arr[i][j];
                      col=j;
                  }
              for(int k=0;k&lt;arr.length;k++)
                  if(arr[k][col]&lt;max)
                  {  flag=1;
                      break;
                  }
              if(flag==0)
              {row=i;
                  break;
              }
          }
          if(flag==0)
              System.out.println("The Position of the Saddle Point is at Row "+(row+1)+"&amp; Column "+(col+1));
          else
              System.out.println("Not found.");
      }
  
      public static void main(String args[])
      {
          int array[][]   ={{12,8,37,15,16},{2,12,21,14,13},{15,47,23,20,19},{65,57,43,21,47}};
          SaddlePoint sadl=new SaddlePoint(array);
          sadl.display(array);
          sadl.findSaddle();
      }
  }
  </code></pre>