title: Add Matrices in Java
body: <p>I need to write a short program on how to add two matrices.. The first matrix should look like this:</p>
  
  <pre><code>1 2 3 4 5 6 7 8 9 10
  11 12 13.......19 20
  21................30
  31................40
  41................50
  etc..
  91...............100
  </code></pre>
  
  <p>But I don't really come to a solution how to increment the first array.. :S</p>
  
  <p>Here is what I got so far:</p>
  
  <pre><code>package uebung05;
  
  public class MatrixAddition
  {
      public static void main(String[] argv)
      {
          int firstArray[][]  = new int[10][10];
          int secondArray[][] = new int[10][10];
          int ergArray[][]    = new int[10][10];
  
          System.out.println("Matrix 1\n----------------------------");
  
          // Inkrementieren der ersten Matrix
          for(int row = 0; row &lt; firstArray.length; row++)
          {
              for(int column = 0; column &lt; firstArray[row].length; column++)
              {
                  // Increment Array here???
                  System.out.print(firstArray[row][column] + "  ");
              }
              System.out.println();
          }
  
          System.out.println("\nMatrix 2\n----------------------------");
  
          // Dekrementieren der zweiten Matrix
          for(int row = 0; row &lt; secondArray.length; row++)
          {
              for(int column = 0; column &lt; secondArray[row].length; column++)
              {
                  // Array mit Werten befüllen
                  secondArray[row][column] = column + 1;
                  System.out.print(secondArray[row][column] + "  ");
              }
              System.out.println();
          }
  
          System.out.println("\nAddition beider Matrizen\n----------------------------");
  
          // Addition firstArray &amp; secondArray
          for(int row = 0; row &lt; ergArray.length; row++)
          {
              for(int column = 0; column &lt; ergArray[row].length; column++)
              {
                  // Addition
                  ergArray[row][column] = firstArray[row][column] +
                                          secondArray[row][column];
  
                  System.out.print(ergArray[row][column] + "  ");
              }
              System.out.println();
          }
      }
  }
  </code></pre>