打印出能被3整除的所有"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。
package com.mbt.lx;
/**
*
* @author shixiang.chen
*/
public class Test4 {
public static void main(String[] args) {
for(int i = 100; i <1000 ; i++) {
if((i%3)==0) {
String str = String.valueOf(i);
char[] array = str.toCharArray();
int count = 0;
for (int j = 0; j < 3; j++) {
int e = Integer.valueOf(Integer.valueOf(String.valueOf(array[j])));
int cube = (int) Math.pow(e, 3);
count = count+cube;
}
if(i==count) {
System.out.println("水仙花数:" + i);
}
}
}
}
}