← all problems

isArmstrongNumber 🌶️🌶️🌶️

An Armstrong number is one where, if you raise each of its digits to the power of the TOTAL NUMBER OF DIGITS and add those up, you get the original number back. For example, 153 has 3 digits, and 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153. Write a method that takes one int parameter, n, and returns true if n is an Armstrong number, or false otherwise. Every single-digit number is trivially an Armstrong number (a single digit raised to the power of 1 is itself).

Precondition: n is 1 or greater.