title: Searching a 2D Array
body: <p>I have instantiated a 2D array of an editable number of rows and a set number of three columns. </p>
  
  <p>It is randomly filled with 0's and 1's using the Random .nextInt(2) method.</p>
  
  <p>After the array is filled, I want to be able to search the array and return the <em>first</em> occurrence of a 0.</p>
  
  <p>How can I do this? </p>
  
  <p>For example, if i had an array that looked something like this: </p>
  
  <ul>
  <li>1 1 0</li>
  <li>0 1 0</li>
  <li>1 1 1 </li>
  </ul>
  
  <p>The first occurence would be at (0,3). I want to search the array horizontally and when it reaches the third column (the end), it will go to the next row.</p>
  
  <blockquote>
    <p>Note: I originally tested the following section of code with a 2D array that was completely filled with 0's and when I manually inserted 1's in the array and then tried to search for the first occurence of a 0 it worked. However, the code doesn't work when the array is randomly filled..</p>
  </blockquote>
  
  <pre><code> public String findNextAvailable()
  { 
      for (int i=0; i&lt;seatlist.length; i++) 
      { 
          for (int j=0; j&lt;seatlist[i].length; j++)
          {
  
              int k=0;
              if (seatlist[0][0]==0) 
              { 
                  nextavailable= seatchart[0][0];
                  break;
              }
              else
              if(seatlist[k][j]==0)
              {
                  nextavailable= seatchart[k][j];
                  break;
              }
              else 
              {   k++;
                  if(seatlist[k][j]==0) 
                  {
                      nextavailable= seatchart[k][j];
                      break;
                  }    
              }
  
          }
      }
      return nextavailable;
  }
  </code></pre>
  
  <p>Thanks in advance! </p>