Program in Java for subtraction of matrices.

Subtraction of Matrices in Java :

Subtraction of matrices is the matrix whose each cell contains the difference of the values of the matrix from another matrix, in their corresponding cell.

e.g.

A(3×3)=[ [1, 2, 3], [4, 5, 6], [7, 8, 9] ]

B(3×3)=[ [11, 22, 33], [44, 55, 66], [77, 88, 99] ]

B-A(3×3)=[ [10, 20, 30], [40, 50, 60], [70, 80, 90] ]

Below is the program to input two matrices and produce a resultant matrix which carries their substraction.

Source Code :

Output :

Enter the size of matrices (nxm) :
2
2
Input Matrix 1 :
25
12
13
1
Input Matrix 2 :
23
56
4
0
Subtraction of Matrices is :
2  -44
9   1

Leave a Reply

Your email address will not be published. Required fields are marked *