// matrix addition import java.util.Scanner; class MA { static void readMatrix(int M[][],int row,int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++){ Scanner sc = new Scanner(System.in); M[i][j]= sc.nextInt(); } } } static void printMatrix(int M[][],int row,int col) { for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) System.out.print(M[i][j] + " "); System.out.println(); } } static int[][] addMatrix(int A[][], int B[][],int row, int col) { int i, j; int C[][] = new int[row][col]; for (i = 0; i < row; i++) for (j = 0; j < col; j++) C[i][j] = A[i][j] + B[i][j]; return C; } public static void main(String[] args) { int row,col; Scanner sc = new Scanner(System.in); System.out.println("Enter the no of rows"); row = sc.nextInt(); System.out.println("Enter the no of col"); col = sc.nextInt(); int[][] A = new int[row][col]; int[][] B = new int[row][col]; System.out.println("Enter the values of Matrix A"); readMatrix(A,row,col); System.out.println("Enter the values of Matrix B"); readMatrix(B,row,col); int C[][] = addMatrix(A, B,row,col); System.out.println("\nResultant Matrix:"); printMatrix(C,row,col); } }