JAVA 身份证验证

 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
 
public class JavaString {
 
       public static void main(String[] args) {
              try {
                     Date time = new Date();
                     int year = time.getYear();
 
                     String str;
                     InputStreamReader stdin = new InputStreamReader(System. in ); // 键盘输入
                     BufferedReader bufin = new BufferedReader(stdin);
 
                     System. out .print( "Input    " );
                     str = bufin.readLine();
                     if (str.length() == 18) {
                            String b = str.substring(8, 10);
                            int c = Integer.parseInt(b);
                            int age = year - c;
                            System. out .println( "Age    " + age);
                     } else {
                            System. out .println( "Input must equales 18 wei!" );
                     }
              } catch (IOException E) {
                     System. out .println( " 发生 I/O 错误 !!!" );
              }
       }
}
 
 

你可能感兴趣的:(JAVA)