Q.13 Find whether the given number is Amstrong Number or not?import java.util.Scanner;
public class Armstrong {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
System.out.println("Enter a Number to check it is a Armstrong Number or Not");
int n=in.nextInt();
in.close();
int a=n,reminder=0,sum=0;
while(a>0){
reminder=a%10;
a=a/10;
sum=sum+reminder*reminder*reminder;
}
if(sum==n){
System.out.println("Given Number "+n+" is a ArmstrongNumber");
}
else
System.out.println("Given Number "+n+" is not an ArmstrongNumber");
}
}
No comments:
Post a Comment