An Armstrong number is an n-digit number that is equal to the sum of the nth powers of its digits.
e.g –
Numbers 1 to 9 (1 digit, so to the power 1)
1^1 = 1, 2^1 = 2, 3^1 = 3
Number 371 (3 digit, so to the power 3)
371 is of 3 digits, so sum of each digits cube should be 371
3^3 + 7^3 + 1^3 = 27 + 343 + 1 = 371
Number 1634 (4 digit, so to the power 4)
1^4 + 6^4 + 3^4 + 4^4 = 1 + 1296 + 81 + 256 = 1634
Let’s see implementation in java
public class Armstrong {
public static void main(String[] args) {
Scanner s = new Scanner(System.in); //371
System.out.println("enter a number - ");
int number = s.nextInt();
int sum=0, rem;
for (int i = number; i > 0; i = i / 10)
{
rem = i % 10;
sum = sum + rem * rem *rem;
}
if(sum==number)
{
System.out.println(number + " is an Armstrong Number\n");
}
s.close();
}
}

