60) Write a program to input a number and check whether it is Armstrong number (Narcissistic Number) or not? (153=13+53+33=1+125+27=153)
import java.util.*;
public class Armstrong
{
public static void main(String args[ ])
{
Scanner sc = new Scanner (System.in);
System.out.println("Enter a number");
int a = sc.nextInt();
int k = a;
int c = 0;
while(k>0)
{
k=k/10;
c++;
}
k = a;
int s = 0;
while(k>0)
{
int d = k%10;
s=s+(int)Math.pow(d,c);
k=k/10;
}
if(s==a)
{
System.out.println("Entered number is a ARMSTRONG Number ");
}
else
{
System.out.println("Entered number is not a ARMSTRONG Number ");
}
}
}
Output :
No comments:
Post a Comment
if you have any doubts, Please let me know.
Your Truly
Shashank Porwal