An Armstrong number has sum of its digits raised to the power of number of digits
equals the number. i.e. An n-digit number equal to the sum of the nth powers of its digits.
The following example shows how to check whether the given number is Armstrong.
/**
* An Armstrong number has sum of digits raised to the power of number of digits
* equals the number
*
* @author Sudhakar KV
*
*/ public class ArmstrongNumber {
private static int getNumOfDigits(int number) { return String.valueOf(number).length();
}
private static boolean isArmstrong(int number) { int orgNumber = number; int sum = 0; int digit = 0; int digitPow = 0; int numOfDigits = getNumOfDigits(number);
List<Integer> digits = new ArrayList<Integer>();
List<Integer> digitPows = new ArrayList<Integer>();
while (number > 0) {
digit = number % 10;
digitPow = (int) Math.pow(digit, numOfDigits);
sum += digitPow;
number = number /10;