title: Paint Fill multidimensional array
body: <p>My goal is a "paint fill" function that one might see on many image editing programs. That is, given a screen (represented by a two-dimensional array of colors), a point, and a new color, fill in the surrounding area until the color changes from the original color.</p>
  
  <p>I've implemented it for a 2D array, and here is the code :</p>
  
  <pre><code>public static void paint (int [][] screen,int OldColor,int NewColor,int y,int x)
      {   
          if(y&gt;screen.length-1||y&lt;0||x&gt;screen[0].length||x&lt;0||screen[y][x]!=OldColor)
            return;
          screen[y][x]=NewColor;
          paint(screen,OldColor,NewColor,y-1,x);
          paint(screen, OldColor, NewColor, y+1, x);
          paint(screen, OldColor, NewColor, y, x-1);
          paint(screen, OldColor, NewColor, y, x+1);
      }
  </code></pre>
  
  <p> </p>
  
  <p>But I want to implement it for multidimensional arrays like 3D that could be solved by adding:</p>
  
  <pre><code>paint(screen, OldColor, NewColor, y, x,z-1);
  paint(screen, OldColor, NewColor, y, x,z+1);
  </code></pre>
  
  <p>But imagine the array is 100 D... How can I solve this problem?</p>