Page 380 - ComputerScience_Class_11
P. 380

Program 12     Write a Java program 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
                            void fillarray()
                14          {

                15              Scanner sc= new Scanner(System.in);
                16              int i, j;

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

                20                  for(j=0; j<s; j++)

                21                  {




                  378  Touchpad Computer Science (Ver. 3.0)-XI
   375   376   377   378   379   380   381   382   383   384   385