02 July, 2012

Find out the given number is Armstrong or not.

import java.util.*;
class Armstrong
{
public static void main(String []args)
{
int sum=0;
Scanner s=new Scanner(System.in);
System.out.print("Enter Number = ");
int n=s.nextInt();
int temp=n;

for(int i=0;i<=n ; i++)
{
int r=n%10;
sum=sum+(r*r*r);
n=n/10;
}

if(sum==temp)
System.out.printf("\n%d is Armstrong",temp);
else
System.out.printf("\n%d is not Armstrong",temp);

}
}

No comments:

Post a Comment

Thank You !