Write a program to print all armstrong number from 1 to n...
Answers
Answered by
7
import java.util.*;
class Sample
{
public static void main(String args[])
{
Scanner demo = new Scanner(System.in);
int a,b,c = 0, d;
System.out.println("Enter a number :");
a = demo.nextInt();
b = a;
while(a > 0)
{
d = a % 10;
c = c+(d*d*d);
a = a/10;
}
if(b == c)
{
System.out.println("Armstrong number");
}
else
{
System.out.println("Not armstrong number");
}
}
}
Output:
Enter a number : 153
Armstrong number.
Hope it helps!
Anonymous:
gud u are intelligent man!!
Similar questions