import java.*;
class Armstrong
{
public static void main(String[] args)
{
int n=0,m=0,sum=0,i,r;
if(args.length>0)
{
for(i=0;i<args.length;i++)
{
try
{
n=Integer.parseInt(args[i]);
m=Integer.parseInt(args[i]);
}
catch(NumberFormatException nfe)
{
System.out.print("\n\nThis "+args[i]+" is not a valid Integer, so considering it 0\n");
n=0;
m=0;
}
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==m)
{
System.out.print("\n\nYes, This "+m+" is Armstrong no.\n\n");
}
else
{
System.out.print("\n\nNo, This "+m+" is not an Armstrong no.\n\n");
}
}
}
}
}
class Armstrong
{
public static void main(String[] args)
{
int n=0,m=0,sum=0,i,r;
if(args.length>0)
{
for(i=0;i<args.length;i++)
{
try
{
n=Integer.parseInt(args[i]);
m=Integer.parseInt(args[i]);
}
catch(NumberFormatException nfe)
{
System.out.print("\n\nThis "+args[i]+" is not a valid Integer, so considering it 0\n");
n=0;
m=0;
}
while(n!=0)
{
r=n%10;
sum=sum+r*r*r;
n=n/10;
}
if(sum==m)
{
System.out.print("\n\nYes, This "+m+" is Armstrong no.\n\n");
}
else
{
System.out.print("\n\nNo, This "+m+" is not an Armstrong no.\n\n");
}
}
}
}
}
No comments:
Post a Comment