Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ttt #577

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Added code for matrix sub
BuildTools committed May 11, 2023
commit c01a041901aa88dd98f86e1a64d4565a35edc4d0
18 changes: 18 additions & 0 deletions java/matrix/matrixSub.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public class MatrixSubExample{
public static void main(String args[]){
//creating two matrices
int a[][]={{1,3,4},{2,4,3},{3,4,5}};
int b[][]={{1,3,4},{2,4,3},{1,2,4}};

//creating another matrix to store the difference of two matrices
int c[][]=new int[3][3]; //3 rows and 3 columns

//Subtracting and printing addition of 2 matrices
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
c[i][j]=a[i][j]-b[i][j]; //use - for subtraction
System.out.print(c[i][j]+" ");
}
System.out.println();//new line
}
}}