title: How do you add adjacent cells in a 2d array?
body: <p>I need to have each cell in the firstArray become the sum of all adjacent cells then dump that answer into secondArray.
  Example:</p>
  
  <p>Initial array with random numbers:</p>
  
  <pre><code>3   5   11  
  5   9   14   
  1   2   8 
  </code></pre>
  
  <p>Computed array:</p>
  
  <pre><code>19  42  41  
  20  49  48  
  33  62  44 
  </code></pre>
  
  <p>3 spot([0][0]) is <code>5 + 9 + 5 = 19</code>, and so on. Here's what I have:</p>
  
  <pre><code>public class ProcessArray {
  
      private int rows;
      private int columns;
      private int [][] firstArray;
      private int [][] secondArray;
  
  
  public ProcessArray(int rows, int columns) {
  
      this.rows=rows;
      this.columns=columns;
      firstArray = new int[rows][columns];
      secondArray = new int[rows][columns];
  
      initializeArray(firstArray, secondArray);
  
      randomlyFillArray(firstArray);
      System.out.println("Initial array with random numbers: ");
      printArray(firstArray, secondArray, rows, columns);
      getFirstArray(firstArray);
      System.out.println("Computed array:");
      computeArrayValues(firstArray);
  
  
  
  }
  
  private void initializeArray(int firstArray[][], int secondArray[][]){
      for(int i = 0; i &lt;firstArray.length; i++){
          for (int j =0; j&lt;firstArray[i].length; j++){
              firstArray[i][j] = (0);
          }
  
      }
      for(int i = 0; i &lt;secondArray.length; i++){
          for (int j =0; j&lt;secondArray[i].length; j++){
              secondArray[i][j] = (0);
          }
  
      }
  }
  
  public void randomlyFillArray(int firstArray[][]){
      for(int i = 0; i &lt;firstArray.length; i++){
          for (int j =0; j&lt;firstArray[i].length; j++){
              firstArray[i][j] = (int)(Math.random()*15);
          }
  
      }
  
  }
  
  //here's where I try to have it add, I don't know what loop to have it run to go to each spot in the `firstArray`:
  
  public void computeArrayValues(int firstArray[][]){
      int x=1;
      int y=1;
      int sum;
  
      int topLeft = firstArray[x-1][y-1];
      int top = firstArray[x][y-1];
      int topRight = firstArray[x+1][y-1];
      int midLeft = firstArray[x-1][y];
      int midRight = firstArray[x+1][y];
      int botLeft = firstArray[x-1][y+1];
      int bot = firstArray[x][y+1];
      int botRight = firstArray[x+1][y+1];
  
      secondArray[0][0]= (bot+botRight+midRight);
  
      for (x=0; x&lt;firstArray.length; x++){
          for(y=0; y&lt;firstArray.length; y++){
      secondArray[x][y] = (topLeft+top+topRight+midLeft+midRight+botLeft+bot+botRight);
          }
      }
      System.out.println(secondArray[x][y]);
  }
  
  public void printArray(int firstArray[][], int secondArray[][], int rows, int columns){
  
      for (int i = 0; i &lt; rows; i++){
          for (int j = 0; j &lt; columns; j++){
              System.out.printf(String.format("%4s", firstArray[i][j]));
          }
          System.out.println();
      }
  
  }
  
  public int[][] getFirstArray(int array[][]){
      array = firstArray;
      return array;
  
  }
  
  public int[][] getSecondArray(int array[][]){
      array = secondArray;
      return array;
  
  }
  </code></pre>
  
  <p>}</p>