0
3.9kviews
Write a program to accept a number from command line and to check whether it is Armstrong or not.
1 Answer
written 8.5 years ago by |
import java.util.*;
class ArmstrongNumber
{
public static void main(String args[])
{
int n, sum = 0, temp, r;
n =Integer.parseInt(args[0]);
temp = n;
while( temp != 0 )
{
r = temp%10;
sum = sum + r*r*r;
temp = temp/10;
}
if ( n == sum )
System.out.println("Entered number is an Armstrong number.");
else
System.out.println ("Entered number is not an Armstrong number.");
}
}