/** * MatrixAdd.java - * Method and test cases for matrix addition. The method * addMatrices computes the sum of two matrices. * * For example: * +- -+ +- -+ +- -+ * |1 2 3| |2 3 4| |3 5 7| * |4 5 6| + |5 4 3| = |9 9 9| * |2 1 0| |0 1 2| |2 2 2| * +- -+ +- -+ +- -+ * * This program also contains a method for displaying an array. */ class matrixAddition { public static void main (String[] args) { int[][] t1 = {{1, 2, 3}, {2, 3, 4}}; int[][] t2 = {{3, 4, 5}, {6, 7, 8}}; int[][] result; result = addMatrices(t1,t2); printMatrix(result); } /** * Add two rectangular matrices of integers and * return a matrix with their sum. */ static int[][] addMatrices(int[][] m1, int[][] m2) { int[][] result = new int[m1.length][m1[0].length]; for (int row=0; row