代码如下 :
package ClassDemo; public class Homework01 {
public static void main(String[] args) {
int maxValue = 1000;
for (int i = 1; i < maxValue; i++) {
String strOfVar = String.valueOf(i);
double sum = 0.0;
for (int j = 0; j < strOfVar.length(); j++)
sum += Math.pow(Double.parseDouble(strOfVar.substring(j, j + 1)), 3.0);
if (sum == (double) i) {
System.out.println(i + "是水仙花数");
}
}
}
}