An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
import java.util.*;
class Armstrong
{
public static void main(String args[])
{
int num,sum=0,t,r;
Scanner sc =new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
t=num;
while(num>0)
{
r=num%10;
sum=sum+r*r*r;
num=num/10;
}
if(sum==t)
System.out.println("Armstrong NO");
else
System.out.println("Not Armstrong NO");
}
}
Output:
Enter the number
371
Armstrong No
import java.util.*;
class Armstrong
{
public static void main(String args[])
{
int num,sum=0,t,r;
Scanner sc =new Scanner(System.in);
System.out.println("Enter the number");
num=sc.nextInt();
t=num;
while(num>0)
{
r=num%10;
sum=sum+r*r*r;
num=num/10;
}
if(sum==t)
System.out.println("Armstrong NO");
else
System.out.println("Not Armstrong NO");
}
}
Output:
Enter the number
371
Armstrong No