import java.util.*;
public class Armstrong
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println("enter a no. to check no is armstrong or not");
int n=scn.nextInt();
int c=0,a,b;
b=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(b==c)
{
System.out.println("number is armstrong" );
}
else
{
System.out.println("no. is not armstrong" );
}
}
}
Output :
enter a no. to check no is armstrong or not
371
number is armstrong
Tags:
Basic