import java.io.*;
class Matrix{
public static void main(String[] args) throws IOException{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nMATRIX :");
System.out.print("\nENTER THE ORDER OF THE MATRIX YOU HAVE : ");
int order=Integer.parseInt(in.readLine());
int[][] A = new int[order][order];
int[][] B = new int[order][order];
int[][] C = new int[order][order];
System.out.println("ENTER ELEMENTS OF Ist MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++){
A[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("ENTER ELEMENTS OF IIst MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++){
B[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("Matrix I: ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println("Matrix II: ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(B[i][j]+" ");
}
}
System.out.println();
int menu = 0;
System.out.println("\n1. ADD\n2. SUBSTRACT\n3. MULTIPLY\n4. DIVISION\n5. QUIT");
boolean quit = false;
do{
System.out.print("ENTER YOUR CHOICE : ");
menu = Integer.parseInt(in.readLine());
System.out.println();
switch(menu) {
case 1:
System.out.println("SUM OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 2:
System.out.println("SUBSTRCTION OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
C[i][j]=A[i][j]-B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 3:
System.out.println("MULTIPICATION OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
for(int k=0;k<order;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
break;
case 4:
System.out.println("DIVISION OF 2 MATRICES : ");
for(int i = 0; i < order; i++) {
for(int j = 0; j < order; j++) {
C[i][j]=A[i][j]/B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println(" ");
}
break;
case 5:
quit = true;
break;
default:
System.out.println("INVALID OPTION !!");
}
}while (!quit);
}
}
class Matrix{
public static void main(String[] args) throws IOException{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nMATRIX :");
System.out.print("\nENTER THE ORDER OF THE MATRIX YOU HAVE : ");
int order=Integer.parseInt(in.readLine());
int[][] A = new int[order][order];
int[][] B = new int[order][order];
int[][] C = new int[order][order];
System.out.println("ENTER ELEMENTS OF Ist MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++){
A[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("ENTER ELEMENTS OF IIst MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++){
B[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("Matrix I: ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println("Matrix II: ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(B[i][j]+" ");
}
}
System.out.println();
int menu = 0;
System.out.println("\n1. ADD\n2. SUBSTRACT\n3. MULTIPLY\n4. DIVISION\n5. QUIT");
boolean quit = false;
do{
System.out.print("ENTER YOUR CHOICE : ");
menu = Integer.parseInt(in.readLine());
System.out.println();
switch(menu) {
case 1:
System.out.println("SUM OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
C[i][j]=A[i][j]+B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 2:
System.out.println("SUBSTRCTION OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
C[i][j]=A[i][j]-B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println();
}
break;
case 3:
System.out.println("MULTIPICATION OF 2 MATRICES :");
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
for(int k=0;k<order;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<order;i++){
for(int j=0;j<order;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
break;
case 4:
System.out.println("DIVISION OF 2 MATRICES : ");
for(int i = 0; i < order; i++) {
for(int j = 0; j < order; j++) {
C[i][j]=A[i][j]/B[i][j];
System.out.print(C[i][j]+" ");
}
System.out.println(" ");
}
break;
case 5:
quit = true;
break;
default:
System.out.println("INVALID OPTION !!");
}
}while (!quit);
}
}