Professional Documents
Culture Documents
static int
mat = new int[3]
3
static int
mat2 = new int[3]
3
static int
result = new int[3]
3
public static void main(String
Creating the object of
args)
random class
Filling first matrix with
Random rand = new Random()
random values
int i = 0
Filling second matrix with
i < mat.length
random values
True False
int j = 0 int i = 0
j++ int i = 0
j < mat2[i].length
False True
True False
int i = 0
j < mat[i].length
False True
True False
MatrixMultiplier thread1 = new MatrixMultiplier(multiply)
j < mat[i].length MatrixMultiplier thread2 = new MatrixMultiplier(multiply)
False True
Thread th2 = new Thread(thread2)
Starting threads Thread th3 = new Thread(thread3)
th1.start()
th2.start()
th3.start()
th1.join()
th2.join()
th3.join()
Exception e
e.printStackTrace() Printing the result
System.out.println("\n\nResult:")
int i = 0
End main
i < result.length End Class
Multiply Class
True False
int j = 0 class Multiply extends MatrixMultiplication
private int i
j < result[i].length private int j
False True
this.i=i
this.j=j
Matrix Multiplication
chance=0
Function
public synchronized void multiplyMatrix()
int sum=0
int a=0
a=0
a<i
True False
sum=0 chance>=i
False
End multiply class
int b=0 chance++
Thread Class
class MatrixMultiplier implements Runnable
b<j private final Multiply mul
True False
a
@Override
public void run()
mul.multiplyMatrix()