public class MyClass {
public static int armstrong(int n) {
int result = 0, remainder;
while(n > 0) {
remainder = n % 10;
n = n / 10;
result += remainder * remainder * remainder;
}
return result;
}
public static void main(String args[]) {
// 153 = 1*1*1 + 5*5*5 + 3*3*3 = 153 = armstrong
for (int i = 1; i <= 500; i++)
if (i == armstrong(i))
System.out.println(i);
}
}
/*
run:
1
153
370
371
407
*/