7 Dec 2017

Write a program in java to check given number is Armstrong or not ?



class ArmstrongNumber
{
          public static void main(String[] args)
          {
                   int num=1563,sum=0,rem=0;
                   int temp=num;
                   while(num>0)
                   {
                             rem=num%10;
                             num=num/10;
                             sum+=(rem*rem*rem);
                   }
                   System.out.println(temp==sum?"armstrong":"not armstrong");
          }
}



Output