Loading...
Loading...
Loading...
A number with k digits is an Armstrong number when the sum of each digit raised to the power k equals the number itself. For example 153 has 3 digits and 1³ + 5³ + 3³ = 153.
Read a and b and print every Armstrong number from a to b, or None if there is none.
None.Math.pow; raise to the power with a loop.Example 1
Input
100 999
Output
153 370 371 407
153, 370, 371 and 407.
Example 2
Input
10 99
Output
None
No two-digit number works.
Try the problem first. Open one hint at a time.
For each number, first count its digits k with a loop on a copy.
Then go over the digits again. For each digit, raise it to the power k with a small inner loop and add it to a total.
Every loop that eats digits must work on its own copy, because it turns the copy into 0.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor