可计算任意位水仙花数
复制代码代码如下:
public static void main(String[] args) {
interno máximo = 10;
for (int len = 1; len <= max; len++) {
System.out.println(getNarc(len, ""));
}
}
StringBuffer estático strb = new StringBuffer();
String estática getNarc(int len, String início) {
for (int número base = 1; número base <= 9; número base++) {
if (len == 2 || lento == 1) {
StringBuffer tmpbuf = new StringBuffer();
tmpbuf.append(iniciar);
for (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);
} else if (len > 2) {
String nextStr = "";
if (nulo! = início) {
nextStr = início + basenum;
} outro {
nextStr = Integer.toString(basenum);
}
getNarc(len - 2, nextStr);
}
}
retornar strb.toString();
}