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