
WAP to Multiplication of matrix in the way if we have the 3*3 matrix then the we create a 4 thread. In 1 thread mul of 1 row and 1,2,3 coloume.In 2 thread mul of 2 row and 1,2,3 coloume In 3 thread mul of 3 row and 1,2,3 coloume and in 4 thread whole mul of two matrix
Matrix 1 : | 1 2 3| | 4 5 6| | 7 8 9| Matrix 2 : |9 8 7| |6 5 4| |3 2 1|
|9+12+9 8+10+6+ 7+8+3 |:thread:1 |36+30+18 32+25+12 28+20+6 |:thread:2 |63+48+27 56+40+18 49+32+9 |:thread:3
Mul of both matrix :and whole mul of two matrix as thread 4 |30 24 18| |84 69 54| |138 114 90|

Java Matrix Multiplication
import java.util.*;
class MatrixMultiplication{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
int[][] A = new int[3][3];
int[][] B = new int[3][3];
int[][] C = new int[3][3];
System.out.println("Enter elements for matrix A : ");
for (int i=0 ; i < A.length ; i++)
for (int j=0 ; j < A[i].length ; j++){
A[i][j] = input.nextInt();
}
System.out.println("Enter elements for matrix B : ");
for (int i=0 ; i < B.length ; i++)
for (int j=0 ; j < B[i].length ; j++){
B[i][j] = input.nextInt();
}
System.out.println("Matrix A: ");
for (int i=0 ; i < A.length ; i++){
System.out.println();
for (int j=0 ; j < A[i].length ; j++){
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Matrix B: ");
for (int i=0 ; i < B.length ; i++){
System.out.println();
for (int j=0 ; j < B[i].length ; j++){
System.out.print(B[i][j]+" ");
}
}
System.out.println();
System.out.println();
System.out.println("Result is: ");
System.out.println();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
C[i][j]+=A[i][k]*B[k][j];
}
}
}
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(+C[i][j]+" ");
}
System.out.println();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.