首页 > 代码库 > 经典的水仙花问题

经典的水仙花问题

代码如下 :

package ClassDemo; public class Homework01 {
public static void main(String[] args) {
int maxValue = http://www.mamicode.com/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 + "是水仙花数");
}
}
}
}

经典的水仙花问题