Page 582 - ComputerScience_Class_11
P. 582

15               for (int i = 0; i < m; i++)

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

                18                   {
                19                       A[i][j] = sc.nextInt();
                20                   }

                21               }
                22               for (int i = 0; i < m; i++)

                23               {
                24                   for (int j = 0; j < n; j++)
                25                   {

                26
                27                       if (i == 0 || i == m - 1 || j == 0 || j == n - 1)

                28                       {
                29                           sum += A[i][j];
                30                       }

                31                   }
                32               }

                33               System.out.println("\nSum of boundary elements: " + sum);
                34           }
                35       }

              The output of the preceding program is as follows:

                     BlueJ: Terminal Window - Java

                 Options

                Enter number of rows (m): 3
                Enter number of columns (n): 3
                Enter 9 positive integers:
                1
                1
                1
                1
                1
                1
                1
                1
                1

                Sum of boundary elements: 8








                  580  Touchpad Computer Science (Ver. 3.0)-XI
   577   578   579   580   581   582   583   584   585   586   587