import java.io.*;
class Matrix
{
int arr[][],m,n;
void fillarray()throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.println("Enter number");
arr[i][j]=Integer.parseInt(x.readLine());
}
}
}
Matrix(int a,int b)
{
m=a;n=b;arr=new int[m][n];
}
void display()
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
Matrix SubMat(Matrix A)throws IOException
{
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;
}
public static void main(String args[])throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter rows");
int a = Integer.parseInt(x.readLine());
System.out.println("Enter columns");
int b=Integer.parseInt(x.readLine());
Matrix A=new Matrix(a,b);
System.out.println("\nEnter Matrix A");
A.fillarray();
Matrix B=new Matrix(a,b);
System.out.println("\nEnter Matrix B");
B.fillarray();
Matrix C=new Matrix(a,b);
System.out.println("\nMatrix A");
System.out.println("----------");
A.display();
System.out.println("\nMatrix B");
System.out.println("----------");
B.display();
System.out.println("\nResultant Matrix");
System.out.println("------------------");
C=A.SubMat(B);
C.display();
}
}
class Matrix
{
int arr[][],m,n;
void fillarray()throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.println("Enter number");
arr[i][j]=Integer.parseInt(x.readLine());
}
}
}
Matrix(int a,int b)
{
m=a;n=b;arr=new int[m][n];
}
void display()
{
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
}
Matrix SubMat(Matrix A)throws IOException
{
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;
}
public static void main(String args[])throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter rows");
int a = Integer.parseInt(x.readLine());
System.out.println("Enter columns");
int b=Integer.parseInt(x.readLine());
Matrix A=new Matrix(a,b);
System.out.println("\nEnter Matrix A");
A.fillarray();
Matrix B=new Matrix(a,b);
System.out.println("\nEnter Matrix B");
B.fillarray();
Matrix C=new Matrix(a,b);
System.out.println("\nMatrix A");
System.out.println("----------");
A.display();
System.out.println("\nMatrix B");
System.out.println("----------");
B.display();
System.out.println("\nResultant Matrix");
System.out.println("------------------");
C=A.SubMat(B);
C.display();
}
}
No comments:
Post a Comment