title: sudoku solver using backtracking
body: <p>I've recently been working on a backtracking sudoku solving algorithm and currently I'd like to ask on how I should go about to change my solve() method from void to a boolean.</p>
  
  <p>I'm using a very simple backtracking algorithm, and it's currently working fine, but I'd rather have a boolean instead of a void, because having a printstack isn't very nice...</p>
  
  <p>Thanks!</p>
  
  <pre><code>public class Backtracking{
  
  
   static int backtrack = 0;
  
  
   //check if valid in row
  protected static boolean validInRow(int row, int value)
  {
     for( int col = 0; col &lt; 9; col++ )
       if( board[row][col] == value )
           return false ;
  
    return true ;
  }
  
    //check if valid in column
  protected static boolean validInCol(int col, int value)
  {
      for( int row = 0; row &lt; 9; row++ )
       if( board[row][col] == value )
          return false ;
  
    return true ;
   }
  
   //check if valid in 3*3
  protected static boolean validInBlock(int row, int col, int value)
  {
    row = (row / 3) * 3 ;
      col = (col / 3) * 3 ;
  
     for( int r = 0; r &lt; 3; r++ )
        for( int c = 0; c &lt; 3; c++ )
         if( board[row+r][col+c] == value )
           return false ;
  
     return true ;
   }
  
  
  
  
        //call other methods
  public void solve(int row, int col) throws Exception
  {
  
     if(row &gt; 8)
       throw new Exception("Solution found") ;
    else
    {
  
       while(board[row][col] != 0)
       {
          if( ++col &gt; 8 )
          {
             col = 0 ;
             row++ ;
  
  
             if( row &gt; 8 )
                throw new Exception( "Solution found" ) ;
          }
       }
  
  
       for(int value = 1; value &lt; 10; value++)
       {
          if(validInRow(row,value) &amp;&amp; validInCol(col,value) &amp;&amp; validInBlock(row,col,value))
          {
             board[row][col] = value;
             new PrintEvent(board);
  
  
  
             if( col &lt; 8 )
                solve(row, col + 1);
             else
                solve(row + 1, 0);
  
             backtrack++;
           }
        }
  
  
        board[row][col] = 0;
  
        }
     }
   }
  </code></pre>