Page 272 - ComputerScience_Class_11
P. 272

18              int temp, digits=0, rem=0, sum=0;

                19              temp=n;
                20              while(temp>0)

                21              {
                22                  temp = temp/10;
                23                  digits++;

                24              }
                25              temp = n;

                26              while(temp>0)
                27              {
                28                  rem = temp % 10;

                29                  sum +=  (Math.pow(rem, digits));
                30                  temp = temp/10;

                31              }
                32              if(n==sum)
                33                  return true;

                34              else
                35                  return false;
                36          }

                37
                38          void display()

                39          {
                40              boolean ch=check_armstrong();
                41              if(ch)

                42                  System.out.println(n+" is an Armstrong Number");
                43              else
                44                  System.out.println(n+" is not an Armstrong Number");

                45          }
                46

                47          public static void main(String[] args)
                48          {
                49              armstrong ob= new armstrong();

                50              ob.input();
                51              ob.display();

                52          }
                53      }




                  270  Touchpad Computer Science (Ver. 3.0)-XI
   267   268   269   270   271   272   273   274   275   276   277