Addition of 2X2 Matrix in Java
CODE:
public class Main {
public static void main(String[] args) {
int a[][]=new int[2][2];
a[0][0]=1;
a[0][1]=2;
a[1][0]=3;
a[1][1]=4;
int b[][]=new int[2][2];
b[0][0]=1;
b[0][1]=2;
b[1][0]=3;
b[1][1]=4;
System.out.print("Addition of 2X2 Matrix:\n");
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
System.out.print(a[i][j]+b[i][j]+" ");
}
System.out.print("\n");
}
}
}
OUTPUT:
Addition of 2X2 Matrix:
2 4
6 8
Comments
Post a Comment