Page 445 - Computer science 868 Class 12
P. 445

public ArmNum(int num)
                       {
                       n = num;
                       l = 0;
                       for(int i =n; i!=0; i/=10)
                       l++;
                       }
                           public  int sum_pow(int i)
                           {
                               if(i<10)
                                   return (int)Math.pow(i,l);
                               return (int)Math.pow(i%10,l)+sum_pow(i/10);
                           }
                           void isArmstrong()
                           {
                           l=Integer.toString(n).length();
                           int sum;
                               if(n==sum_pow(n))
                               {
                                   System.out.println(n+" IS AN ARMSTRONG NUMBER");
                               }
                               else
                               {
                                   System.out.println(n+" IS NOT AN ARMSTRONG NUMBER");
                               }
                           }
                           public static void main(String[] args)
                           {
                               int num=0,sum=0,noOfDigits=0;
                               Scanner sc=new Scanner(System.in);
                               System.out.println("ENTER THE NUMBER");
                               num=sc.nextInt();
                               ArmNum obj = new ArmNum(num);
                               obj.isArmstrong();
                           }
                       }
                    7.  The following function Mystery( ) is a part of some class. What will the function Mystery( ) return when the value of num=43629,
                       x=3 and y=4 respectively? Show the dry run/working.                                       [ISC 2019]
                       int Mystery (int num, int x, int y)
                       {
                       if(num<10)
                       return num;
                       else
                       {
                       int z = num % 10;
                       if(z%2 == 0)
                       return z*x + Mystery (num/10, x, y);
                       else
                       return z*y + Mystery(num/10, x, y);
                       }
                       }

                                                                                                                       443
                                                                                                           Recursion   443
   440   441   442   443   444   445   446   447   448   449   450