import java.util.*;
class ArmstrongNumber
{
public static void main(String args[])
{
int n, sum = 0, temp, r;
Scanner in = new Scanner(System.in);
System.out.println("Enter a number to check if it is an armstrong number");
n = in.nextInt();
temp = n;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( n == sum )
System.out.println("Entered number is an armstrong number.");
else
System.out.println("Entered number is not an armstrong number.");
}
}
Output

Like this:
Like Loading...
Related
Armstrong Program in C++
Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits is equal to the number itself.
For example 153 is armstrong number, 132 is not prime number.Armstrong program in c++ is very simple and easy to write.