 Hello friends. I am Sanjay Gupta. I welcome you on my channel. You can watch various programming related videos on my channel. So search it, subscribe it for updates. It contains more than 800 videos. In this video, I am going to demonstrate you matrix multiplication in Java. So I have written two three lines in front of you. It is importing util package which contains scanner class. Then I am going to define matrix multiplication class. Inside this class, I am going to define main function. This main function will be containing all the instructions. So first I am going to declare three 2D arrays, variable ij. Now I am going to allocate memory for three 2D arrays. So this way I have allocated memory for ABC 2D arrays. I have provided row and column sizes three. You can also read these row and column values from user. I have demonstrated that in my other videos, you can watch those videos. Now to read values from user, I need instance of scanner class. So for that purpose, I am writing this statement. Now I have to read elements from user. So the masses and the first matrix will be displayed to read values from user. I am writing nested loop here. I is responsible for rows and J will be responsible for column indexes. So line number 13, 14, 15 are responsible for reading values for a matrix. Now I am copying these statements and I have pasted them. So these instructions will be for reading second matrix values. So this way I have written the instructions which will read values for a matrix and values for B matrix. Now I have to write instructions for matrix multiplication. So first I am implementing i loop. Inside this loop, I am implementing J loop. The logic of matrix multiplication says that row of first matrix, first row of first matrix will be multiplied with first column of second matrix. So here in this logic, I have to implement one more loop K. Inside this loop, I am going to apply multiplication logic before starting K loop. I am assigning 0 as initial value for Cij index because it will be containing matrix multiplication addition. So now I am writing Cij equals to Cij plus. So the multiplication result will be added into Cij location and that multiplication will be of Aik with Bkj location. So this way I have implemented the matrix multiplication logic. So line number 22 to line number 32. This is the logic for matrix multiplication. All the results will be stored in C matrix. So after completion of this loop, I am going to display output on output screen. So this system.output println will be displaying multiplication result masses. Now I have to write INJ loops for printing output in matrix format. So I have copied them. These two loops will be printing values which are available in C matrix and that is containing multiplication result. So here I am writing system.out.print then Cij then backslash t. This statement system.out.print will be printing first row of C matrix on output screen in single line because I am using print only println prints all the elements in new lines but print prints all the elements in a single line. So after completion of J loop, I am going to move the cursor to the new line. So for that I will be using system.out.println. So this way these two loops are responsible for printing the result which is available in C matrix. So I have written the complete code for matrix multiplication in Java. Now I need to compile and execute this code. You can see I am compiling and executing this code. I have to enter values for two matrix. So I am entering one in force matrix. So all the values of force matrix are one. In second I am also entering one as all the elements. You can see the multiplication result. It is three three three three three three three. It means C matrix all indexes are containing three as matrix multiplication result. So if you multiply two matrix which are containing one as all the elements then the multiplication result will be three. So I hope you have understood how we can multiply two matrix in Java. If you want to follow my YouTube channel you can subscribe it. Thank you for watching this video.