Page 314 - computer science (868) class 11
P. 314

Program 12     Write a program in Java to create 3 matrices, and store the elements in two different matrices
                               A and B of order 3 × 3. Find the product of both the matrices and store the result in another
                               matrix and display the result matrix. [Do the program using class and object]
                               For example:

                               Array 1
                                 1    2     3
                                 4    5     6
                                 1    2     3

                               Array 2
                                 2    3     4
                                 1    5     3
                                 6    5     3

                               Third array after multiplying
                                22    28   19
                                46    67   49
                                22    28   19


                1       import java.util.*;
                2       class multiplication

                3       {
                4           int m[ ][ ],n[ ][ ],p[ ][ ];

                5           int s;
                6           multiplication(int size)

                7           {
                8               s=size;

                9               m=new int[s][s];
                10              n=new int[s][s];

                11              p=new int[s][s];
                12          }

                13
                14          void fillarray()

                15          {
                16              Scanner sc= new Scanner(System.in);

                17              int i, j;
                18              System.out.println("Enter elements in the 1st array: ");
                19              for(i=0; i <s; i++)





                312312  Touchpad Computer Science-XI
   309   310   311   312   313   314   315   316   317   318   319