8 queen backtrack ( n change )
<p>The question is when my program backtracks it somehow changes n to n-1 
Could you tell me in which line of my code that happens. 
Example: </p>

<ol>
<li>22 Step 0 2 4 1 3 6 0 0 n in bool -> 5 n in bool -> 5 i = 7 n -> 5</li>
<li>23 Step 0 2 4 1 3 7 0 0 n in bool -> 5 n in bool -> 5 n in bool -> 5 i = 4 n -> 4</li>
<li>24 Step 0 2 4 1 4 7 0 0 n in bool -> 4 i = 5 n -> 4</li>
</ol>

<hr>

<p>As we can see I have n = 5 in step 22, and in step 23 I get n = 4;
Question : How does n in my code go to n-1?</p>

<p>Source(Code doesn't have any errors):</p>

<pre><code>import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;

public class Queens {

    public static FileOutputStream Output;
    public static PrintStream file;
    public static int z = 1;
    public static String[] LentosRaides = {"a", "b", "c", "d", "e", "f", "g", "h"};
    public static String[] LentosSkaiciai = {"8", "7", "6", "5", "4", "3", "2", "1"};

    /***********************************************************************
     * Grazinam true jei kitu valdoviu padietis q[n] nesikonfliktuoja su kitomis
     * valdovemis q[0] iki q[n-1]
     ***********************************************************************/
    public static boolean arNuoseklus(int[] q, int n) {
        for (int i = 0; i &lt; n; i++) {
            System.out.println("n in bool -&gt; " + n);
//            System.out.println("i = " +i+ "n = " +n);
//            System.out.println("q[i] = "+q[i]+" q[n] = "+q[n]);
//            System.out.print("q[i] - q[n] = ");
//            System.out.println(q[i] - q[n]);
//            System.out.print(" q[n] - q[i] = ");
//            System.out.println(q[n] - q[i]);
//            System.out.println();


            if (q[i] == q[n]) {
                return false;   // tapati skiltis(kolona)
            }
            if ((q[i] - q[n]) == (n - i)) {
                return false;   // ta pati pagrindine diagonale major

            }
            if ((q[n] - q[i]) == (n - i)) {
                return false;   // ta pati mazesnine diagonale minor
            }

        }
        return true;
    }

    /***********************************************************************
     * Spausdinimas i tekstini faila: Rezultatai.txt ir i output'a
     ***********************************************************************/
    public static void printQueens(int[] q) {
        int N = q.length;
        String Temp[] = new String[N];
        System.out.println(z);
        for (int y = 0; y &lt; N; y++) {
            Temp[y] = (LentosRaides[q[y]] + LentosSkaiciai[y]);
        }

        Arrays.sort(Temp);
        System.out.println(Arrays.asList(Temp));
        file.print(z);
        file.println(Arrays.asList(Temp));
        z++;

        for (int j = 0; j &lt; N; j++) {
            System.out.print(q[j] + " ");
        }

//        System.out.println(" ");
//        System.out.print(" ");
//
//        for (int u = 0; u &lt; N; u++) {
//            System.out.print(" " + LentosRaides[u]);
//        }
//
//        System.out.println();
//
//        for (int i = 0; i &lt; N; i++) {
//            System.out.print(LentosSkaiciai[i] + " ");
//            for (int j = 0; j &lt; N; j++) {
//
//                if (q[i] == j) {
//                    System.out.print("V ");
//                } else {
//                    System.out.print("* ");
//                }
//            }
//
//            System.out.println();
//        }


        System.out.println();
    }

    /***********************************************************************
     *  Visu kombinaciju bandimas naudojant "backtracking'a"
     *  numeravimas -&gt; bandimas pastatyti Valdove nuo 0 iki 7 pozicijos
     *  naudojant patikrinima arNuoseklus
     ***********************************************************************/
    public static void numeravimas2(int N) {
        int[] a = new int[N];
        numeravimas(a, 0);

    }

    public static void numeravimas(int[] q, int n) {
        System.out.println("n -&gt; " + n);
        int N = q.length;

        if (n == N) {
            printQueens(q);
          //  System.out.println("o/ ");

        } else {
            for (int i = 0; i &lt; N; i++) {
                q[n] = i;
                System.out.println(" i =  " + i);
                System.out.println("n -&gt; " + n);
                printQueens(q);
                if (arNuoseklus(q, n)) {
                    numeravimas(q, n + 1);
                }
            }
        }
    }

    public static void main(String[] args) {
        int N = 8;

        try {
            Output = new FileOutputStream("Rezultatai.txt");
            file = new PrintStream(Output);
        } catch (Exception e) {
            System.out.println("Neimanoma pasiekti failo");
        }

        numeravimas2(N);

    }
}
</code></pre>
