using same variable in recursion
<p>I'm trying to apply the flood fill on a specific question. I'm having a hard time understanding how to create a variable with a help function so I keep it throughout all the recursion.<br>
I've seen there is a thread about it though I don't know how to apply it for my own use.  </p>

<p>This is the code I wrote so far:</p>

<p>how do I create the k variable to stay the same?</p>

<pre><code>public static int[][] fill(int[][] map, int i, int j, int color) {
    int[][] ans = null;

        if ((i&lt;map.length)&amp;&amp;(i&gt;0)&amp;&amp;(j&lt;map.length)&amp;&amp;(j&gt;0))
            {
            if ((k!=map[i][j]))

                    {
                        map[i][j]=color;    
                    }
            }
        fill(map,i-1,j,color);
        fill(map,i+1,j,color);
        fill(map,i,j-1,color);
        fill(map,i,j+1,color);
    return ans;
}

public static void fill(int[][] map, int i, int j, int color,int k)

k=map[i][j] 
</code></pre>

<p>lets say this is my array: </p>

<p>4, 1, 2, 2<br>
4, 4, 3, 1<br>
1, 4, 4, 4 </p>

<p>1, 4, 0, 2</p>

<p>and I wish to flood fill all the indexes that have the value of 4.
I wish k to obtain the value of 4 so I can use k to compare in each index.</p>
