Java calculation of arbitrary number of daffodils sample (palindrome number) _java

Source: Internet
Author: User

Can calculate the number of daffodils of arbitrary bit

Copy Code code as follows:

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.