J2SE: Obtain the user's gender through the ID card number!

Source: Internet
Author: User

@ Value indicates the ID card number entered by the user.

I only know that when the number at the end of the ID card number is an odd number, the gender is male; when the number is an even number, the gender is female.
However, in some special cases, for example, if the last digit is a letter,
One is X and the other is E, both are male, so I am trying to judge it as a special case, ladies and gentlemen, you
Do you usually encounter similar situations? Do you use the ID card number for additional features? Help me, because I don't
You know the gender of the user whose last ID card number is another letter.
Thank you!

Public String execute (String value)
{
Value = value. trim ();
If (value = null | (value. length ()! = 15 & value. length ()! = 18 ))
{
Return "";
}
If (value. length () = 15 | value. length () = 18)
{
String lastValue = value. substring (value. length ()-1, value. length ());
Int sex;
If (lastValue. trim (). toLowerCase (). equals ("x") | lastValue. trim (). toLowerCase (). equals ("e "))
{
Return "Mr ";
}
Else
{
Sex = Integer. parseInt (lastValue) % 2;
Return sex = 0? "Lady": "Mr ";
}
}
Else
{
Return "";
}
}
Finished!

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.