Page 581 - ComputerScience_Class_11
P. 581

54              int size = sc.nextInt();

                   55              Magic magicObj = new Magic(size);
                   56              magicObj.input();

                   57              magicObj.find_magic();

                   58          }
                   59      }


                 The output of the preceding program is as follows:


                       BlueJ: Terminal Window - Java
                   Options

                  Enter the size of the array: 5
                  Enter 5 integers:
                  289
                  123
                  57
                  987
                  111
                  Magic numbers in the array:
                  289



                   Program 10    Write a program to declare a matrix A[ ][ ] of order (m * n), where 'm' is the number of rows
                                 and 'n' is the number of columns, such that both m and n are greater than 2 and less than 20.
                                 Allow the user to input positive integers into this matrix. Display the sum of only the boundary
                                 elements of the original matrix.
                   1       import java.util.Scanner;
                   2

                   3       public class BoundarySum
                   4       {

                   5           public static void main(String args[])
                   6           {
                   7               Scanner sc = new Scanner(System.in);

                   8               System.out.print("Enter number of rows (m): ");
                   9               int m = sc.nextInt();

                   10              System.out.print("Enter number of columns (n): ");
                   11              int n = sc.nextInt();
                   12              int A[][] = new int[m][n];

                   13              int sum = 0;
                   14              System.out.println("Enter " + (m * n) + " positive integers:");





                                                                                                Internal Assessment  579
   576   577   578   579   580   581   582   583   584   585   586