# Armstrong Numbers

I gave the final for my CSCI 1302 class earlier today, and for one of the questions I asked them to write a program, in Java, that prints out all the Armstrong numbers without using any String methods. An Armstrong number is a 3 digit number for which the sum of the cubes of its digits is equal to the number. An example of an Armstrong number is 153 as 153 = 1 + 125 + 27 = 1^3 + 5^3 + 3^3. The final was supposed to be cumulative (and it was), and this just screamed 1301 material (Sorry for the UGA rhetoric. CSCI 1301 is the prerequisite for my class.). Here is the solution that I came up with when I encountered this question in an interview one time.

Since the definition of a 3 digit number seems to depend on who you're talking too, I always make sure to mention that the code can be easily modified to only work with true 3 digit numbers. Also, since Scala is my favorite language, here is the same code converted to Scala.

Another interesting approach is to enumerate all 3 digit numbers and use what I call the modulus technique to get the digits for each (mod 10 to get the last digit, divide by 10 to decrease the number by one digit, repeat). I suspected (correctly) that some of my students would think of this method because it's very similar to a lab in the prerequisite course.

If you know any other method to enumerate Armstrong numbers then please post it in the comments.