Page 450 - computer science (868) class 11
P. 450

39               }
                40               return s;

                41           }
                42           //main method

                43           public static void main(String args[])
                44           {

                45               Scanner sc=new Scanner(System.in);
                46               Smith ob=new Smith();

                47               int n,sum1,sum2;
                48               System.out.println("Checking whether a number is a Smith Number or not ");

                49               System.out.print("Enter a number = ");
                50               n = sc.nextInt();
                51               if(ob.composite(n)){

                52                   sum1 = ob.sum_of_digits(n);

                53                   sum2 = ob.sum_prime(n);
                54                   if(sum1 == sum2)
                55                       System.out.println(n + " is a Smith Number.");

                56                   else
                57                       System.out.println(n + " is not a Smith Number.");

                58               }
                59               else

                60                   System.out.println(n + " is not a Smith Number.");
                61           }    //end of main

                62       }     //end of class



              The output of the preceding program is as follows:
              Output 1
              Checking whether a number is a Smith Number or not
              Enter a number = 666
              666 is a Smith Number.
              Output 2
              Checking whether a number is a Smith Number or not
              Enter a number = 14
              14 is not a Smith Number.
                                                         Variable Description
                 NAME         TYPE                                       DESCRIPTION
               n           int          To store the number

               flag        int          Flag variable



                448448  Touchpad Computer Science-XI
   445   446   447   448   449   450   451   452   453   454   455