Question

# Share code with your friends

Code

```				```
import java.util.Scanner;
public class Matrix
{
Scanner sc=new Scanner(System.in);
int arr[][];
int m,n;
Matrix(int mm,int nn)
{
m=mm;
n=nn;
arr=new int[m][n];
}

void fillarray()
{

for(int i=0;i< m;i++)
{
for(int j=0;j< n;j++)
{
arr[i][j]=sc.nextInt();
}
}
}

Matrix SubMat(Matrix A)
{
Matrix B=new Matrix(m,n);
for(int i=0;i< m;i++)
{
for(int j=0;j< n;j++)
{
B.arr[i][j]=A.arr[i][j]-arr[i][j] ;
}
}
return B;
}

void display()
{
for(int i=0;i< m;i++)
{
System.out.println();

for(int j=0;j< n;j++)
System.out.print(arr[i][j]+"\t");
}
}

public static void main()
{
Scanner sc1=new Scanner(System.in);
System.out.println("Size of array:");
int x=sc1.nextInt();

int y=sc1.nextInt();
if(x>25 ||y>25)
{
System.out.println("Invalid Size" );
}
else
{
Matrix P=new Matrix(x,y);
Matrix Q=new Matrix(x,y);
Matrix R=new Matrix(x,y);
System.out.println("ENTER ELEMENTS IN MATRIX P");
P.fillarray();
System.out.println("ENTER ELEMENTS IN MATRIX Q");
Q.fillarray();
System.out.println("MATRIX P - MATRIX Q");
R=Q.SubMat(P);
R.display();
}

}
}

```
```

Sale

50
Sale

150
Sale

200
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50
Sale

50