Java Program to Subtract Two Matrices

To subtract two matrices in Java Programming, you have to ask to the user to enter the two matrix, then start subtracting the matrices i.e., subtract matrix second from the matrix first like mat1[0][0] - mat2[0][0], mat1[1][1] - mat2[1][1]and so on. Store the subtraction result in the third matrix say mat3[0][0], mat3[1][1] and so on,

Example 1:



Output :

enter Matrix 1 Elements : 9
8
7
7
8
9
9
8
7
enter Matrix 2 Elements : 3
2
1
1
2
3
3
2
1
Subtracting Matrices (i.e. Matreix1 - Matrix2)...
Result of Matrix1 - Matrix2 is:
6 6 6
6 6 6
6 6 6

Example 2:



Output :

0 0 0
0 0 0
2 2 1