public class ShuiXianTest {
/**
* i 被取N位数的整数
* j 取第N个位数
*/
public int gewBit(int i,int j){
String strI = String.valueOf(i);
if(strI.length()<=j){
return 0;
}
return Integer.parseInt(String.valueOf(strI.charAt(j)));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int result = 153;
ShuiXianTest test = new ShuiXianTest();
for(int i=0;i<999;i++){
int a = test.gewBit(i, 0);
int b = test.gewBit(i, 1);
int c = test.gewBit(i, 2);
if(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)==i){
System.out.println("a="+a+" b="+b+" c="+c+" i="+i);
}
}
}
}
水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)