Page 509 - Cs_withBlue_J_C11_Flipbook
P. 509

10              int n=sc.nextInt();
                   11

                   12              if(m<2 || n<2 || m>20 || n>20)

                   13                   System.out.println("Rows and columns should be more than 2 and less
                                         than 20.");
                   14              else
                   15              {
                   16                  int a[][]=new int[m][n];

                   17                  int i,j,x,t,c;

                   18                  System.out.println("Enter "+m*n+" elements for the matrix : ");
                   19                  for(i=0;i< m;i++)
                   20                  {

                   21                      for(j=0;j< n;j++)
                   22                          a[i][j]=sc.nextInt();

                   23                  }
                   24                  System.out.println("\nOriginal Matrix : ");

                   25                  for(i=0;i< m;i++)
                   26                  {

                   27                      for(j=0;j< n;j++)
                   28                          System.out.print(a[i][j]+" ");

                   29
                   30                      System.out.println();

                   31                  }
                   32

                   33                  int b[]=new int[2*m+2*n-4];
                   34                  x=0;

                   35                  //STORE THE ELEMENTS OF THE OUTER ROW AND COLUMN
                   36                  //IN A 1-D ARRAY

                   37                  for(i=0;i< m;i++)
                   38                  {

                   39                      for(j=0;j< n;j++)
                   40                      // CONDITION FOR BOUNDARY ELEMENTS
                   41                          if(i==0 || j==0 || i==m-1 || j==n-1)

                   42                              b[x++]=a[i][j];

                   43                  }



                                                                                                                       507
                                                                                                   Internal Assessment  507
   504   505   506   507   508   509   510   511   512   513   514