Java Program to Check the Armstrong numbers
![]() |
Armstrong number |
Armstrong number
A number will be called Armstrong if the sum of cubes of each digits is equal to the original number.
Program
import java.util.Scanner;
public class Armstrong
{
public static void main(String args[])
{
Scanner ob=new Scanner(System.in);
System.out.println("Enter the number to be checked.");
int num=ob.nextInt();
int a,i,sum=0;
i=num;
while(num!=0)
{
a=num%10;
sum=sum+a*a*a;
num=num/10;
}
if(sum==i)
System.out.println(i+" is an Armstrong Number.");
else
System.out.println(i+" is not a Armstrong Number.");
}
}