Write a program to multiply the given matrices.
Input (Two Dimensional matrix) | Output (Two Dimensional matrix) |
---|---|
-2 -4 3 |
-4 -7 -10 |
4 5 1 |
62 121 |
-5 -6 |
null |
{}(EMPTY ARRAY) |
null |
null |
null |
{{1, 2}, {2, 1}} |
null |
null |
null |
class AdvanceMatrixMultiplication
{ public static void main(String s[])
{
int firstArray[][] = {{-2, -4, 3}, {-1, 2, 2}, {5, 4, 3}};
int secondArray[][] = {{6, 7, 8}, {1, 2, 3}, {4, 5, 6}};
int multiplicationArray[][] = multiplyMatrices(firstArray, secondArray);
if (multiplicationArray != null) {
System.out.println("Resultant matrix is :");
for (int[] array1d : multiplicationArray) {
for (int element : array1d) {
System.out.print(element + " ");
}
System.out.println();
}
} else {
System.out.println("The matrix multiplication can not be performed due to invalid input data.");
}
}
public static int[][] multiplyMatrices(int firstMatrix[][], int secondMatrix[][]) {
//Write code here to get the multiplication of given matrices and return the resultant matrix.
}
}
Topic: Learn Arrays And Loops