import java.util.*;
class Armstrong
{
public static void main(String args[])
{
int r,s,cube,sum=0;
System.out.println("Enter a Number:");
Scanner a=new Scanner(System.in);
int num =a.nextInt();
s=num;
while(num>0)
{
r=num%10;
num=num/10;
cube=r*r*r;
sum=sum+cube;
}
if(sum==s)
{
System.out.println("Number is Armstrong");
}
else
{
System.out.println("Number is not Armstrong");
}
}
}
class Armstrong
{
public static void main(String args[])
{
int r,s,cube,sum=0;
System.out.println("Enter a Number:");
Scanner a=new Scanner(System.in);
int num =a.nextInt();
s=num;
while(num>0)
{
r=num%10;
num=num/10;
cube=r*r*r;
sum=sum+cube;
}
if(sum==s)
{
System.out.println("Number is Armstrong");
}
else
{
System.out.println("Number is not Armstrong");
}
}
}
No comments:
Post a Comment