



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Date of Performance: 31.10. Date of Submission: 31.10. Submitted By Name : Anjuman Ara Ananna ID : 193002008 Section : DC Batch : 193 Date : 31.10. Submitted To Feroza Naznin Senior Lecturer Dept. of CSE Green University of Bangladesh Marks Obtained Remarks
Class Test: 01 Problem Name: Write a java program to Add Two Matrix Using Multi- dimensional Array of objects. Objectives:
int B[][] = { { 1, 1, 1, 1 }, { 2, 2, 2, 2 }, { 3, 3, 3, 3 }, { 4, 4, 4, 4 } }; int C[][] = new int[4][4]; int rowSize=4; int colSize=4; void printMatrix(int M[][], int rowSize, int colSize) { for (int i = 0; i < rowSize; i++) { for (int j = 0; j < colSize; j++) System.out.print(M[i][j] + " "); System.out.println(); } } static int[][] add(int A[][], int B[][],
int size) { int i, j; int C[][] = new int[size][size]; for (i = 0; i < size; i++) for (j = 0; j < size; j++) C[i][j] = A[i][j] + B[i][j]; return C; } int[][] add(int M[][]){ int C[][] = add(A, B, 4); System.out.println("\nResultant Matrix:"); printMatrix(C, 4, 4); return null; } }
Output: Discussion: We have done the problem in object oriented programming. We have calculated the sum of two matrixes using Multi-dimensional array of objects and print the addition very carefully. We learnt from our lab report that, how to add two matrixes using array of objects in oriented programming.