package javaCodes;
import java.util.Scanner;
public class matrix_multiplication {
public static int[][] multiplication(int arr[][], int arr1[][], int size)
{
int[][] array = new int[3][3];
for(int i=0; i<size; i++)
{
for(int j=0; j<size; j++)
{
for(int k=0; k<size; k++)
{
array[i][j] += arr[i][k]*arr1[k][j];
}
}
}
return array;
}
public static void main(String args[])
{
int[][] arr = new int[3][3];
int[][] arr1 = new int[3][3];
int[][] arr2 = new int[3][3];
Scanner sc = new Scanner(System.in);
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
arr[i][j] = sc.nextInt();
arr1[i][j] = sc.nextInt();
}
}
arr2 = multiplication(arr, arr1, 3);
for(int i=0; i<3; i++)
{
for(int j=0; j<3; j++)
{
System.out.print(arr2[i][j]+" ");
}
System.out.println("\n");
}
}
}
No comments:
Post a Comment