Page 392 - CA_Blue( J )_Class10
P. 392

27                  {   pr =pr * ar[i][j]; }
                28              }

                29          }
                30          System.out.println("Sum of left diagonal : "    +   sl);

                31          System.out.println("Product of right diagonal : "   +   pr);
                32      }

                33  }

              You will get the following output:
              Enter the size : 2
              Enter a number : 1
              Enter a number : 2
              Enter a number : 3
              Enter a number : 4
              Original Array :
              1 2
              3 4
              Sum of left diagonal : 5
              Product of right diagonal : 6

                              To input ten numbers in an array and a number to search and print whether the number is
                Program 11
                              present in the array or not. (Use Linear Search technique)

                 1  import java.util.*;

                 2  class linear_search
                 3  {

                 4      public static void main()
                 5      {

                 6          Scanner sc= new Scanner(System.in);
                 7          int ar[]=new int[10];
                 8          int n,i,p=-1;

                 9          for (i=0; i<10; i++)

                10          {   System.out.print("Enter a number : ");
                11              ar[i] =sc.nextInt();
                12          }

                13          System.out.print("Enter a number to search : ");
                14          n=sc.nextInt();

                15          for(i=0;i<10;i++)
                16          {   if(ar[i]==n)



                390390  Touchpad Computer Applications-X
   387   388   389   390   391   392   393   394   395   396   397