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, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
Code
// Program to check whether a given Number is
// ArmStrong Number or not.class ArmstrongTest
{
public static void main( String args[ ] )
{
int r, n, x, sum;
n = 153;
x = n;
sum = 0;
while( n != 0 )
{
r = n % 10;
sum = sum + ( r * r * r );
n = n / 10;
}
if( sum == x )
System.out.println( " Number " + x + " is a Amstrong Number." );
else
System.out.println( " Number " + x + " is NOT a Amstrong Number." );
}
}
Output:Number 153 is a Amstrong Number.