//matrix1 double[][] matrix1 = {{1, 2, 3},{4, 5, 6},{7, 8, 9}}; //matrix2 double[][] matrix2 = {{0, 2, 4},{1, 4.5, 2.2},{1.1, 4.3, 5.2}}; addMatrix(matrix1, matrix2); printArrays(matrix1, matrix2, result, '+'); }//end of main public static double[][] addMatrix(double[][] a, double[][] b){ double[][] result = {{a[0][0]+b[0][0], a[0][1]+b[0][1], a[0][2]+b[0][2]}, {a[1][0]+b[1][0], a[1][1]+b[1][1], a[1][2]+b[1][2]}, {a[2][0]+b[2][0], a[2][1]+b[2][1], a[2][2]+b[2][2]}}; return result; } public static void printArrays(double[][] m1, double[][] m2, double[][] m3, char op) { for (int i = 0; i < m1.length; i++) { for (int j = 0; j < 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 < 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 < m3[0].length; j++) { System.out.print(" " + m3[i][j]); } System.out.println(); } } // public static void printArrays(double[][] a) { // for(int row = 0; row < a.length; row++){ // for (int col = 0; col < a[row].length; col++) { // // System.out.print(a[row][col] + " "); // }//end of inner for loop // System.out.println(""); // //}//end of outer for loop // }//end of printArrays }//end of class