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

Program 15    Define a class Mirror_matrix to input and print the mirror of a user-defined matrix. The data
                                 members and member methods are defined as follows:
                                 Data Members
                                 int a[][]                       :  to store the array
                                 int n                           :  to store the size of the matrix
                                 Member Methods
                                 void input()                    :  to input the array
                                 void mirror()                   :  to find the mirror of the matrix and print it
                                 Write the main method to call the methods and print the mirror of the matrix.


                   1       import java.util.*;
                   2       class Mirror_matrix
                   3       {

                   4           int n;
                   5           int a[][];

                   6
                   7           void input()

                   8           {
                   9               Scanner sc=new Scanner(System.in);

                   10              System.out.println("enter the size of the matrix");
                   11              n=sc.nextInt();

                   12              //System.out.println("enter the number of columns of the matrix");
                   13              //c=sc.nextInt();

                   14              System.out.println("enter array elements");
                   15              a=new int[n][n];

                   16              for(int i=0;i<n;i++)
                   17              {

                   18                  for(int j=0;j<n;j++)
                   19                  {

                   20                      a[i][j]=sc.nextInt();
                   21                  }

                   22              }
                   23          }
                   24

                   25          void mirror()

                   26          {
                   27              int p=0,q=n-1;



                                                                                                                       477
                                                                                                   Internal Assessment  477
   474   475   476   477   478   479   480   481   482   483   484