Page 391 - CA_Blue( J )_Class10
P. 391

Original Array :
                 1 2 3
                 4 5 6
                 7 8 9
                 Transposed Array :
                 1 4 7
                 2 5 8
                 3 6 9

                                 To input elements in an array of size m x m and print the sum of left diagonal and product of the
                  Program 10
                                 right diagonal.

                   1  import java.util.*;
                   2  class array_double_diagonal
                   3  {   public static void main()

                   4      {   Scanner sc= new Scanner(System.in);

                   5          int i,j,m,sl=0,pr=1;
                   6          System.out.println("Enter the size : ");
                   7          m=sc.nextInt();

                   8          int ar[][]=new int[m][m];
                   9          for (i=0; i<m; i++)

                  10          {   for(j=0;j<m;j++)
                  11              {   System.out.print("Enter a number : ");

                  12                  ar[i][j] = sc.nextInt();
                  13              }

                  14          }
                  15          System.out.println("Original Array :");

                  16          for (i=0; i<m; i++)
                  17          {   for(j=0;j<m;j++)

                  18              {  System.out.print(ar[i][j]+" ");   }
                  19              System.out.println();

                  20          }
                  21

                  22          for (i=0; i<m; i++)
                  23          {   for(j=0;j<m;j++)

                  24              {  if(i==j)
                  25                  {   sl=sl+ar[i][j];   }

                  26                  if((i+j)==(m-1))



                                                                                                                       389
                                                                                                              Arrays   389
   386   387   388   389   390   391   392   393   394   395   396