java盤算隨意率性位水仙花數示例(回文數)。本站提示廣大學習愛好者:(java盤算隨意率性位水仙花數示例(回文數))文章只能為提供參考,不一定能成為您想要的結果。以下是java盤算隨意率性位水仙花數示例(回文數)正文
可盤算隨意率性位水仙花數
public static void main(String[] args) {
int max = 10;
for (int len = 1; len <= max; len++) {
System.out.println(getNarc(len, ""));
}
}
static StringBuffer strb = new StringBuffer();
static String getNarc(int len, String start) {
for (int basenum = 1; basenum <= 9; basenum++) {
if (len == 2 || len == 1) {
StringBuffer tmpbuf = new StringBuffer();
tmpbuf.append(start);
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 (null != start) {
nextStr = start + basenum;
} else {
nextStr = Integer.toString(basenum);
}
getNarc(len - 2, nextStr);
}
}
return strb.toString();
}