所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个“水仙花数”,因为153=1的三次方+5的三次方+3的三次方。
public class Flower {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a, b, c, e;
char[] d;
String q;
for (int i = 100; i < 1000; i++) {
q = i + "";
// d = q.toCharArray();
a = Integer.parseInt(String.valueOf(q.charAt(0)));
b = Integer.parseInt(String.valueOf(q.charAt(1)));
c = Integer.parseInt(String.valueOf(q.charAt(2)));
e = (int) (Math.pow(a, 3) + Math.pow(b, 3) + Math.pow(c, 3));
// System.out.println(a);
if (e == i) {
System.out.println(i);
}
q = null;
d = null;
}
}
}