Loading...
Loading...
An Armstrong number equals the sum of its digits, each raised to the power of the number of digits. For example, 153 has 3 digits and 1³ + 5³ + 3³ = 153.
Print every Armstrong number from L to R. Build it from three small methods: static int countDigits(int n), static long power(int base, int exp) (a loop, not Math.pow) and static boolean isArmstrong(int n).
NONE.Example 1
Input
100 999
Output
153 370 371 407
The four 3-digit Armstrong numbers.
Example 2
Input
10 99
Output
NONE
No 2-digit number works.
Try the problem first. Open one hint at a time.
countDigits: divide by 10 until the number becomes 0, counting the steps.
isArmstrong: get the digit count once, then add power(digit, count) for each digit and compare with n.
To print with single spaces, print a space before every number except the first; keep a boolean found to know whether to print NONE.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor