Respuesta :
Answer:
// Java profram to perform Arithmetic operations on square matrices
// Comments are used for explanatory purpose
// Program starts here
import java.util.*;
import java.io;
public class Matrices {
// Multiply Method Here
static void multiply(int mat1[][],int mat2[][], int mulmat[][])
{
int i, j, k;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
mulmat[i][j] = 0;
for (k = 0; k < N; k++)
mulmat[i][j] += mat1[i][k] * mat2[k][j];
}
}
System.out.println("Result matrix" + " is ");
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
System.out.print( mulmat[i][j] + " ");
System.out.println();
}
}
// Subtraction Method here
static void sub(int mat1[][],int mat2[][], int submat[][])
{
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
addmat[i][j]=mat1[i][j]-mat2[i][j]; //
System.out.print(submat[i][j]+" ");
}
}
// Addition Method here
static void add(int mat1[][],int mat2[][], int addmat[][])
{
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
addmat[i][j]=mat1[i][j]+mat2[i][j]; //
System.out.print(addmat[i][j]+" ");
}
}
// Main Method Starts here
public static void main (String [] args)
{
Scanner input = new Scanner (System.in);
// Declare type of square matrix
int N;
// input N
lbl: N = input.nextInt();
if(N>=2 && N<=6)
{
int mulmat[][] = new int[N][N] ;
int addmat[][] = new int[N][N] ;
int submat[][] = new int[N][N] ;
// Multiplication
mulmat(mat1, mat2, mulmat);
// Addition
addmat(mat1, mat2, addmat);
// Subtraction
submat(mat1, mat2,submat);
}
else
{
goto lbl;
}
}