Java Common algorithm questions (24)

Source: Internet
Author: User

 PackageCom.xiaowu.demo;//a 5-digit number, judging whether it is a palindrome number. That is, 12321 is a palindrome number, single-digit and million-bit the same, 10 bits and thousands of the same.  Public classDemo24 { Public Static voidMain (string[] args) {F2 (123454321); }    //Method One     Public Static voidF1 (intN) {if(n >= 10000 && N < 100000) {String s=string.valueof (n); Char[] C =S.tochararray (); if(C[0] = = C[4] && c[1] = = C[3]) {System.out.println (n+ "is a palindrome number. "); } Else{System.out.println (n+ "not a palindrome number. "); }        } Else{System.out.println (n+ "not a 5-digit number!!! "); }    }    //Method Two     Public Static voidF2 (intN) {BooleanFlag =true; String s=long.tostring (n); Char[] C =S.tochararray (); intj =c.length;  for(inti = 0; i < J/2; i++) {            if(C[i]! = c[j-i-1]) {flag=false; }        }        if(flag) {SYSTEM.OUT.PRINTLN (n+ "is a palindrome number. "); } Else{System.out.println (n+ "not a palindrome number. "); }    }}

Java Common algorithm questions (24)

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.