title: Algebra: add two matrices
body: <p>Well I'm trying to add two matrices but my math is wrong and I think I'm out of ideas on how to get it right. I feel absolutely stupid that I can't figure this out, but my head hurts and I'm all out of options</p>
  
  <pre><code>import java.util.Scanner;
  public class AddMatrices
  {
     public static void main(String[] args)
     {
        Scanner input = new Scanner(System.in);
  
        int N = 3;
  
        System.out.print("Enter matrix1: ");
        double[][] matrix1 = new double[3][3];
        for (int i = 0; i &lt; matrix1.length; i++) {
           for (int j = 0; j &lt; matrix1[i].length; j++) {
              matrix1[i][j] = input.nextDouble();
           }
        }
  
        System.out.print("Enter matrix2: ");
        double[][] matrix2 = new double[3][3];
        for (int i = 0; i &lt; matrix1.length; i++) {
           for (int j = 0; j &lt; matrix1[i].length; j++) {
              matrix2[i][j] = input.nextDouble();
           }
        }
  
        double[][] resultMatrix = addMatrix(matrix1, matrix2);
        System.out.println("The addition of the matrices is ");
        printResult(matrix1, matrix2, resultMatrix, '+');
     }
  
     public static double[][] addMatrix(double[][] m1, double[][] m2)
     {
        double[][] result = new double[m1.length][m1[0].length];
        for (int i = 0; i &lt; result.length; i++) {
           for (int j = 0; j &lt; result[0].length; j++)
              m1[i][j] += m2[i][j];
        }
        return result;
     }
  
     public static void printResult(double[][] m1, double[][] m2, double[][] m3, char op)
     {
        for (int i = 0; i &lt; m1.length; i++) {
           for (int j = 0; j &lt; m1[0].length; j++) {
              System.out.print(" " + m1[i][j]);
           }
           if (i == m1.length / 2)
              System.out.print(" " + op + " ");
           else {
              System.out.print(" ");
           }
           for (int j = 0; j &lt; m2[0].length; j++) {
              System.out.print(" " + m2[i][j]);
           }
           if (i == m1.length / 2)
              System.out.print(" = ");
           else {
              System.out.print(" ");
           }
           for (int j = 0; j &lt; m3[0].length; j++) {
              System.out.print(" " + m3[i][j]);
           }
           System.out.println();
        }
     }
  }
  </code></pre>