Program to find the Armstrong Number in java

What is Armstrong Number?

An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number since 1**3 + 5**3 + 5**3 = 153.

write a program to find the Armstrong Number in java

import java.util.*;
public class ArmstrongNum {
   public static void main(String args[])
   {
    Scanner s=new Scanner(System.in);
    int n,r,d=0,temp;
    System.out.println(“enter a number”);
    n=s.nextInt();
    temp=n;
    while(n!=0)
    {
        r=n%10;
        d=d*d*d+r;
        n=n/10;
    }
    if(temp==d)
        System.out.println(“armstrong number”);
     else
        System.out.println(” not armstrong”);
   }
}
Next Important  palindrome Program click here

Leave a Reply