public class Armstrong {
public static void main(String[] args)
{
int n=153,r;
int sum=0;
int n1;
n1=n;
while(n!=0)
{
r=n%10;
sum=sum + r*r*r;
n=n/10;
}
if (n1==sum)
System.out.println("the given number is Armstrong");
else
System.out.println("the given number is not Armstrong");
}
}
OUTPUT:
C:\java>javac Armstrong.java C:\java>java Armstrong the given number is Armstrong
Simple Java program for finding a number is Armstrong or not, here the value is predefined. The same program can be re written using functions by dynamically reading values.