idcard身份证号码

package com.test.idcard;
import java.util.*;
import java.io.*;
import java.math.*;
public class IDnumber2{
 public static boolean checklong(String s){
  boolean t=false;
  try{
     long num=Long.parseLong(s);
     t=true;
        }catch(Exception e){
     t=false;
        }
        return t;
    }
 public static void main(String args[]){
  try{
   while(true){
   System.out.println("请输入身份证号码,以回车结束:");
   BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   String s=br.readLine();
   if(s.length()==15){
    int total=0;
       char f;
       boolean t=checklong(s);
                if(t){ 
                        System.out.println("这是一个旧号码!");
                        StringBuffer s1=new StringBuffer(s).insert(6,"19");
            StringBuffer s2=new StringBuffer(s1).append("0");
                     for(int i=1;i<=18;i++){
                       char c=s2.charAt(18-i);
                      String s3=String.valueOf(c);
                      int ai=Integer.parseInt(s3);
                      double b=Math.pow(2,(i-1));
                      int wi=(int)(b)%11;
                      System.out.println("i="+i+'\t'+"ai="+ai+'\t'+"wi="+wi);
                      total+=ai*wi;
                        }
                     total=total%11;
                        char Check[]={'1','0','X','9','8','7','6','5','4','3','2'};
                        String str4=String.valueOf(Check[total]);            StringBuffer str5=new StringBuffer(s2).deleteCharAt(17);
         StringBuffer str6=new StringBuffer(str5).append(str4);
              System.out.println("转化后的18位新号码为:"+str6);
           }
           else{
            System.out.println("你输入有误!");
          }
   }
   else if(s.length()==18){
    String s1=new String(s).substring(0,17);
    boolean f=checklong(s1);
    if(f){
     char c=s.charAt(17);
     if((c=='X')||(c<='9'&&c>='0')){
      int total=0;
               char k; 
         StringBuffer s2=new StringBuffer(s1).append("0");
         for(int i=1;i<=18;i++){
                       char c1=s2.charAt(18-i);
                      String s3=String.valueOf(c1);
                      int ai=Integer.parseInt(s3);
                      double b=Math.pow(2,(i-1));
                      int wi=(int)(b)%11;
                      total+=ai*wi;
                     
                        }
                     total=total%11;
                        char Check[]={'1','0','X','9','8','7','6','5','4','3','2'};
                     if(c==Check[total]){
              System.out.println("这是一个新号码!");
            String year=s.substring(6,10);
            String month=s.substring(10,12);
            String date=s.substring(12,14);
            System.out.println("此人的生日是:"+year+"年"+month+"月"+date+"日");
            String day=s1.substring(6,10);
            int b=Integer.parseInt(day);
            Calendar rightNow=Calendar.getInstance();
            int yearNow=rightNow.get(Calendar.YEAR);
            int age=yearNow-b;
            System.out.println("此人的年龄是:"+age);
            if((s.charAt(16))%2==0){
             System.out.println("此人的性别是:女");
            }
            else{
         System.out.println("此人的性别是:男");
            }
            }
            else{
             System.out.println("你输入有误!");
            }
           }
       }
       else{
        System.out.println("你输入有误!");
        }
    }
    else{
        System.out.println("你输入有误!");
        }
       System.out.println();
       System.out.println();
   }
  }catch(IOException e){}
 }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值