logo CodeStepByStep logo

armstrongNumbers

Language/Type: Java for

Write a method named armstrongNumbers that accepts an integer n as a parameter and prints all n-Armstrong numbers. An n-Armstrong number is a number containing exactly n digits where the sum of each digit raised to the nth power equals the number itself. For example, 153 is a 3-Armstrong number because 13 + 53 + 33 = 153. The call of armstrongNumbers(3); should print the following console output:

153 370 371 407

If n is 0 or negative, or if there are no n-Armstrong numbers, print no output.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.