 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, it contains more than 800 videos. In this video I am going to demonstrate you Matrix Edition and Subtraction in Java. So first of all I am going to import a class scanner which is available in util package. Then I am defining a class matrix sum sub. Inside this class I am going to define main function definition and inside this main function all the required statements will be available. So first of all I am going to declare 3 2d arrays. Now allocating memory to these 2d arrays. Right now I am providing size as 3 3, low size is 3 and column size is also 3. You can also read these row and column sizes from user. I have demonstrated those in my another videos. You can watch them. How you can read row and column size from user. Now I am going to create instance of scanner class so that I can read values from user with the help of this instance. So this message and the first matrix will be displayed on output screen to read values from user. I am going to, sorry, I am going to repeat these nested loops. I have implemented 2 loops. i and j, i is responsible for low index, j is responsible for column indexes. I am declaring these variables here. Now aij equals to input dot next end. So line number 13, 14 and 15 are responsible for reading first matrix from user. I have copied 4 statements and I am modifying them to read second matrix. So line number 17, 18, 19 and 20 are responsible for reading second matrix. Now I am going to calculate some and I will be printing that sum on output screen. So the message addition will be displayed. Now I again require these nested loops so I am copying them. Inside this j loop I am going to perform addition. So cij equals to aij plus bij. This is addition of a and b matrix and the result is assigned into c. Now I am going to print this on output screen. You can notice that I have used only print instead of print element. So this print will display all the values on same line. So J loop is responsible for printing row values. So if you are printing first row, then you will need all values in a single line. That's why I am using print only. After printing first row, I need to move the cursor to the second line. So after completion of J loop, I am writing system.out.print element. So this statement will bring cursor to the new line. So this way all the addition will be stored inside c matrix as well as it will be displayed on output screen with the help of system.out.print statement. Now for subtraction purpose, you can copy line number 22-231 and paste it. Here instead of addition, you can write subtraction and in place of plus, you can write minus sign. So this way I have implemented the complete code in front of you which adds two matrix and subtracts two matrix as well as output will be displayed on output screen. After implementation, I am going to execute this code. You can see I am compiling and executing this code. It is asking for values. So in first matrix, I am entering four as all the elements. So nine times I have to add four. Sorry, I have to enter four. And in second matrix, I am entering two nine times. It means in my first matrix, all elements are four. In my second matrix, all elements are two. You can see the addition. Six is printed at each location of matrix and subtraction. Two is printed at each location of matrix. So this way the code is working properly. It is leading to matrix from user and printing their addition and subtraction. I hope you have understood whatever I have demonstrated you in this video. If you want to follow my YouTube channel, you can subscribe it. Thank you for watching this video.