Armstrong Number
371, as 3^3 + 7^3 + 1^3 = 371
1634, as 1^4 + 6^4 + 3^4 + 4^4 = 1634
Sample Input 1 :
103
Sample Output 1 :
false
import java.util.Scanner;
import java.math.*;
public class Armstrong {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n=s.nextInt();
int t=n;
int num=n;
int c=0;
// d=0;
int sum=0;
while(num>0)
{
c++;
num=num/10;
}
while(n>0)
{
sum=(int)(sum+(Math.pow(n%10, c)));
n=n/10;
}
if(t==sum)
{
System.out.println("true");
}
else
{
System.out.println("false");
}
}
}
Comments
Post a Comment