Home >>Java Programs >Find an Armstrong Number in Java
In this example, we will see a Java program through which we will find if a given input number is an Armstrong number or not.
Any given positive number can be an Armstrong number if it is equal to the sum of the cubes of its digits for example 0, 1, 153, etc.
Program
class Main
{
public static void main(String[] args)
{
int c=0,a,temp;
int n=407;//It is the number to check armstrong
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c)
System.out.println("Given number is armstrong number");
else
System.out.println("Not armstrong number");
}
}