Java 2D array error
<p>So I need to take a 2D array do calculations to each elements and transfer that into another 2D array while using the values to the "left" "right" "up" and "down" of the current element. If the current element is on the edge (x = 0, y = 0, x = array.length , y = array.length) I will get an array out of bounds error. I want to create a for loop that deals with each of those cases but I don't know how to do it. A sample of my code is</p>

<pre><code>private void buildE(int[][] array, int y, int x)
{

    int up = array[y - 1][x];
    int down = array[y + 1][x];
    int left = array[y][x - 1];
    int right = array[y][x + 1];

    if(up == 0){

        buildETopRow(array);

    }
</code></pre>

<p>E will be my new array. This method does not work because y does not equal 0, it just doesn't exist but I can't set ints to null either. In the case of an out of bounds error I need the element (up, down, left, or right) that is out of bounds to equal the current element. Is there a way I can still use a for loop for this or do I need to do something else?</p>
