Obtain the age of the person who owns the ID number according to the ID number

Source: Internet
Author: User

to obtain the age of the person to whom the social Security number belongs,
And in the method throws the ID number empty exception, the ID number format exception. This method is called in the Main method,

and catches the exception, outputting the associated exception information.


Code:

Package exception;


Import Java.util.Scanner;


public class Shenfen {


public static void Main (string[] args) {
TODO auto-generated Method Stub
Scanner cc = new Scanner (system.in);
String str;
System.out.println ("Please enter your ID number:");
str = Cc.next ();
Cc.close ();
int len = Str.length ();
if (len = = 18) {
int year = Integer.parseint (str.substring (6, 10));
int age = (2014-year) + 1;
System.out.println ("Your Age is:" + ages);
}else
{

try{
Throw Yearexception ();
}catch (Exception e) {
E.printstacktrace ();
}
}
}


private static Exception yearexception () {
TODO auto-generated Method Stub
SYSTEM.OUT.PRINTLN ("You entered the ID card account is wrong, prompt: Empty number, digital wrong, or the format is not correct");
return null;
}


}

Obtain the age of the person who owns the ID number according to the ID number

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.