您好,欢迎来到小侦探旅游网。
搜索
您的当前位置:首页Java身份证代码

Java身份证代码

来源:小侦探旅游网


package IDcard;

import java.util.Scanner;

import java.util.regex.Pattern;

public class IDcard {

public static void main(String[] args){

Scanner input=new Scanner(System.in);

System.out.print(\"请输入身份证号\");

String id=input.next();

String year=new String();

String month=new String();

String day=new String();

String code=new String();

// String code1=id.substring(0, 6);

if(id.length()==15){

year=id.substring(6, 8);

month=id.substring(8, 10);

day=id.substring(10, 12);

code=id.substring(12);

System.out.println(shunxu(code));

birthday(year,month,day);

if(birthday(year,month,day).length()!=0){

System.out.println(birthday(year,month,day));

System.out.println(\"该身份证是旧假的\");

}

else{

System.out.println(shunxu(code));

System.out.println(\"该居民的生日为\"+year+\"年\"+month+\"月\"+day+\"日\");

System.out.println(\"该身份证是旧的\");

}

}

else if(id.length()==18){

year=id.substring(6, 10);

month=id.substring(10, 12);

day=id.substring(12, 14);

code=id.substring(14, 17);

char code2=id.charAt(17);

String code4 = String.valueOf(code2);

birthday(year,month,day);

if(birthday(year,month,day).length()!=0||jiaoyan(id,code4).length()==10){

System.out.println(birthday(year,month,day));

System.out.println(jiaoyan(id,code4));

System.out.println(\"该身份证是假的\");

}

else{

System.out.println(shunxu(code));

System.out.println(\"该居民的生日:\"+year+\"年\"+month+\"月\"+day+\"日\");

System.out.println(jiaoyan(id,code4));

System.out.println(\"该身份证是真的\");

}

}

else{

System.out.println(\"该身份证是假的\");

}

}

public static String address(String code1){

String s=new String();

String code11=code1.replace(\"11\北京\").replace(\"12\天津\").replace(\"13\河北\").replace(\"14\山西\")

.replace(\"15\\"内蒙古\").replace(\"21\\"辽宁\").replace(\"22\\"吉林\").replace(\"23\黑龙江\")

.replace(\"31\\"上海\").replace(\"32\\"江苏\").replace(\"33\\"浙江\") .replace(\"34\安徽\")

.replace(\"35\\"福建\").replace(\"36\\"江西\").replace(\"37\\"山东\").replace(\"37\山东\")

.replace(\"42\\"湖北\").replace(\"43\\"湖南\").replace(\"44\\"广东\").replace(\"45\广西\")

.replace(\"46\\"海南\").replace(\"50\\"重庆\").replace(\"51\\"四川\").replace(\"52\贵州\")

.replace(\"53\\"云南\").replace(\"\\"\").replace(\"61\\"陕西\").replace(\"62\甘肃\")

.replace(\"63\\"青海\").replace(\"\\"宁夏\").replace(\"65\\"\").replace(\"71\\")

.replace(\"82\\").replace(\"91\国外\").replace(\"81\\");

if(code11.equals(code1)){

s=\"该身份证地址编码是错的\";

}

else{

s=\"该身份证省份为:\"+code11;

}

return s;

}

public static String birthday(String year,String month,String day){

int i=Integer.parseInt(year);

int j=Integer.parseInt(month);

int z=Integer.parseInt(day);

StringBuffer error1 =new StringBuffer();

String error=new String();

if (i > 2015 || i == 0) {

error= \"该身份证年份是错的 \";

error1.append(error);

}

if ( j> 12 || j == 0) {

error= \"该身份证月份是错的 \";

error1.append(error);

}

if (z > 31 || z == 0) {

error= \"该身份证日期是错的 \";

error1.append(error);

}

String error2 =new String(error1);

return error2;

}

public static String shunxu(String code){

int i=Integer.parseInt(code);

String s=new String();

if(i%2==0){

s=\"性别:女 \";

}

else{

s=\"性别:男\";

}

return s;

}

public static String jiaoyan(String id,String code4){

int s=0;

Integer[] w = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};

String a=new String();

for(int i=0;i<17;i++){

int ai=Integer.parseInt(String.valueOf(id.charAt(i)) );

int wi=w[i];

s+=ai*wi;

};

int b=s%11;

String b1=String.valueOf(b);

String b0=\"目\"+b1;

String b2=b0.replace(\"目10\\"2\").replace(\"目0\\"1\").replace(\"目1\\"0\").replace(\"目2\目3\

.replace(\"目4\目5\目6\目7\

.replace(\"目8\目9\

if(b2.equals(code4)){

a=\"该身份证验证码是正确的\";

}

else{

a=\"该身份证验证码是错的\";

}

return a;

}

}

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- xiaozhentang.com 版权所有 湘ICP备2023022495号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务