Add

Check Armstrong Number in Java

8:19:00 PM Rohit Kumar Verma 0 Comments

Check Armstrong Number in Java

Armstrong number is a three digit number that the sum of the cube of its individual digits is equal to the number itself. for eg. 371. 3*3*3+7*7*7+1*1*1

class CheckArmstrong{
 public static void main(String[] args)  {
   int a,b=0,temp;
   int input=153;
   temp=input;
   while(input>0)
   {
   a=input%10;
   input=input/10;
   b=b+(a*a*a);
   }
   if(temp==b)
   System.out.println("armstrong number");  
   else
       System.out.println("Not armstrong number");  
  }

0 comments: