Algorithm for Armstrong Number:
step 1:Set s=0
step 2: Read num
step 3: Set b=num
step 4: Repeat through step-7 while num greater than 0
step 5: r=num%10
step 6: s=s+(r*r*r)
step 7: num=num/10
step 8: If b equals to s then print “it is an Armstrong number”
Else print “it is not an Armstrong number”
step 9: Exit
Here is the Java Example for Armstrong Number:
import java.util.Scanner;
public class ArmstrongNumber
{
public static void main(String args[])
{
Scanner s1=new Scanner(System.in);
int num,b,s=0,r;
System.out.println("Enter A Number");
num =s1.nextInt();
b= num;
while(num>0)
{
r= num%10;
s=s+(r*r*r);
num = num/10;
}
if (b==s)
System.out.println(b+" is an Armstrong Number");
else
System.out.println(b+" not an Armstrong Number");
}
}