Programming Examples
Java program to pass an integer as argument and check whether it is Armstrong number or not
Write a program to pass an integer as argument and check whether it is Armstrong number or not. Numbers whose sum of the cube of its digit is equal to the number itself is called Armstrong numbers. Example 153=13+53 +33.
Solution
class Armstrong
{
public static void main(int a)
{
int i,d,s=0;
for(i=a;i>9;i=i/10)
{
d=i%10;
s=s+d*d*d;
}
if(s==a)
System.out.println("Armstrong Number");
else
System.out.println("Not an Armstrong Number");
}
}
Output