Find Number of possible solutions Sudoku Java
<p>I'm trying to find possible solutions of a Sudoku, and it always tells me: 0.</p>

<p>I have to do it with backtracking, and I don't know where is the problem, this is the code:</p>

<pre><code>import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PracticaDAA3 {

    public static boolean Cumple(int[][] matriz, int numero, int[] posicion) {
        int x = posicion[0];
        int y = posicion[1];
        for (int i = 0; i &lt; 9; i++) {
            if (matriz[i][y] == numero) {
                return false;
            }
        }
        for (int j = 0; j &lt; 9; j++) {
            if (matriz[x][j] == numero) {
                return false;
            }
        }
        if (x &lt; 3 &amp;&amp; y &lt; 3) {
            for (int k = 0; k &lt; 3; k++) {
                for (int l = 0; l &lt; 3; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 2 &amp;&amp; x &lt; 6 &amp;&amp; y &lt; 3) {
            for (int k = 3; k &lt; 6; k++) {
                for (int l = 0; l &lt; 3; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 5 &amp;&amp; y &lt; 3) {
            for (int k = 6; k &lt; 9; k++) {
                for (int l = 0; l &lt; 3; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &lt; 3 &amp;&amp; y &gt; 2 &amp;&amp; y &lt; 6) {
            for (int k = 0; k &lt; 3; k++) {
                for (int l = 3; l &lt; 6; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 2 &amp;&amp; x &lt; 6 &amp;&amp; y &gt; 2 &amp;&amp; y &lt; 6) {
            for (int k = 3; k &lt; 6; k++) {
                for (int l = 3; l &lt; 6; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 5 &amp;&amp; y &gt; 2 &amp;&amp; y &lt; 6) {
            for (int k = 6; k &lt; 9; k++) {
                for (int l = 3; l &lt; 6; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &lt; 3 &amp;&amp; y &gt; 5) {
            for (int k = 0; k &lt; 3; k++) {
                for (int l = 6; l &lt; 9; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 2 &amp;&amp; x &lt; 6 &amp;&amp; y &gt; 5) {
            for (int k = 3; k &lt; 6; k++) {
                for (int l = 6; l &lt; 9; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        } else if (x &gt; 5 &amp;&amp; y &gt; 5) {
            for (int k = 6; k &lt; 9; k++) {
                for (int l = 6; l &lt; 9; l++) {
                    if (matriz[k][l] == numero) {
                        return false;
                    }
                }
            }
        }

        return true;
    }

    public static void siguientePosicion(int[] xy) {
        int x = xy[0];
        int y = xy[1];
        //if(x&lt;9 &amp;&amp; y&lt;9){
        if (y == 8) {
            xy[1] = 0;
            xy[0]++;
            //System.out.println("xy0: "+xy[0]+" xy1: "+xy[1]);
        } else
            xy[1]++;

    }

    public static void ResolSudoku(int[] xy, int[][] matriz, int[] solucion) {
        int x = xy[0];
        int y = xy[1];
        if (x &lt; 9 &amp;&amp; y &lt; 9) {
            if (matriz[x][y] == 0) {      //entramos por aqui si hay un 0
                for (int i = 1; i &lt; 10; i++) {
                    if (Cumple(matriz, i, xy)) { //aqui compruebo si mifila o columna o matriz tiene un nº
                        matriz[x][y] = i;
                        //System.out.println("xy0: "+xy[0]+" xy1: "+xy[1]);
                        if (x == 8 &amp;&amp; y == 8)
                            solucion[0]++;
                        else {
                            int[] xy2 = new int[2];
                            xy2[0] = x;
                            xy2[1] = y;
                            siguientePosicion(xy2);
                            ResolSudoku(xy2, matriz, solucion);
                        }
                        matriz[x][y] = 0;
                    }
                }
            } else {
                siguientePosicion(xy);
                // System.out.println("X: "+x);
                //System.out.println("x,y: "+x+y);
                ResolSudoku(xy, matriz, solucion);
            }
        }
    }

    /**
     * @param args the command line arguments
     * @throws java.io.IOException
     */
    public static void Imprimir(int[][] m) {
        for (int i = 0; i &lt; 9; i++) {
            System.out.println();
            for (int j = 0; j &lt; 9; j++) {
                System.out.print(m[i][j] + " ");

            }
        }
    }

    public static void main(String[] args) throws IOException {
        int[][] matriz = new int[9][9];
        int[] xy = new int[2];
        xy[0] = 0;
        xy[1] = 0;
        BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
        for (int i = 0; i &lt; 9; ++i) {
            String[] lista = entrada.readLine().split(" ");
            for (int j = 0; j &lt; 9; j++) {
                matriz[i][j] = Integer.parseInt(lista[j]);
            }
        }
        int[] solucion = new int[1];
        solucion[0] = 0;
        ResolSudoku(xy, matriz, solucion);
        System.out.println(solucion[0]);
        Imprimir(matriz);
    }

}
</code></pre>

<p>I know that with this input:</p>

<pre><code>5 3 4 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9
</code></pre>

<p>The output must to be 1, but my result is 0.</p>

<p>Any ideas?</p>