Page 529 - Cs_withBlue_J_C11_Flipbook
P. 529

The output of the preceding program is as follows:
                 enter the size of the matrix
                 3
                 enter array elements
                 1
                 2
                 3
                 4
                 5
                 6
                 7
                 8
                 9
                 ORIGINAL MATRIX
                 1      2      3
                 4      5      6
                 7      8      9
                 MIRROR MATRIX
                 3      2      1
                 6      5      4
                 9      8      7


                                                            Variable Description
                   NAME         TYPE                                       DESCRIPTION
                  a          int          To store the array
                  i          int          Loop variable

                  j          int          Loop variable
                  b          int          To store the mirror matrix




                   Program 16    Define a class Spiral_Matrix to input and print the spiral of a user-defined matrix (2-D array).
                                 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 array
                                 Member Methods
                                 void input()                    :  to input the size of the array
                                 void spiral()                   :  to find the spiral matrix and print it
                                 Write the main method to call the methods and print the spiral of the matrix.


                   1       import java.util.*;
                   2       class Spiral_Matrix

                   3       {
                   4           int n;

                   5
                   6           void spiralprint(){



                                                                                                                       527
                                                                                                   Internal Assessment  527
   524   525   526   527   528   529   530   531   532   533   534