可计算任意位水仙花数
复制代码代码如下 :
public static void main (String[] arguments) {
int max = 10 ;
pour (int len = 1; len <= max; len++) {
System.out.println(getNarc(len, ""));
}
}
static StringBuffer strb = new StringBuffer();
chaîne statique getNarc (int len, début de chaîne) {
pour (int basenum = 1; basenum <= 9; basenum++) {
si (len == 2 || len == 1) {
StringBuffer tmpbuf = new StringBuffer();
tmpbuf.append(début);
pour (int j = 0; j < len; j++) {
tmpbuf.append(basenum);
}
tmpbuf.append(new StringBuffer(start).reverse().toString());
strb.append(tmpbuf);
strb.append("/n");
// System.out.println(tmpbuf);
} sinon si (len > 2) {
Chaîne nextStr = "" ;
if (null != début) {
nextStr = début + basenum ;
} autre {
nextStr = Integer.toString(basenum);
}
getNarc(len - 2, nextStr);
}
}
return strb.toString();
}