idCard

时间:2022-05-24 05:23:23 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。


import java.io.*;

public class ID{

private String temp ;

private final char[] cc = {1,0,'X',9,8,7,6,5,4,3,2}; public String getID(){ try{

System.out.println("Input ID,please [input]");

BufferedReader br = new BufferedReader(new InputStreamReader( System.in));

temp = br.readLine(); }

catch(IOException e){}

System.out.println(" make sure of it:"+temp); return temp; }

public void checkit(){ String temp1 = temp; if(temp1.length() == 18){

System.out.println(temp1.substring(6,10)+"year "+ temp1.substring(10,12)+"month "+ temp1.substring(12,14)+"day "+

"sex: "+checkSex(temp1.charAt(16)) ); }

else if(temp1.length() == 15){ String id = makeit(temp1);

System.out.println(id.substring(6,10)+"year "+ id.substring(10,12)+"month "+

id.subSequence(12,14)+"day "+ "sex: "+ checkSex(id.charAt(16))); } else

System.out.println("your input is Error,please input again!"); }

public String checkSex(char c){ if(c%2 == 0) return "girl"; else

return "boy"; }

public int LastNum(String temp3){






int index = 0;

for(int i = 16;i>= 0;i--){

double wi = Math.pow(2,(i-1)) %11; int ai = (int)temp3.charAt(i); index += ai*wi; }

index = index % 11;

index = (int)this.cc[index]; return index; }

public String makeit(String temp2){

StringBuffer temp3 = new StringBuffer(temp2); temp3.insert(6,"19");

temp3.insert(17,LastNum(temp3.toString())); return temp3.toString(); }

public static void main(String[] args){ ID id = new ID(); id.temp = id.getID(); id.checkit(); } }






本文来源:https://www.wddqw.com/doc/61e30ea00029bd64783e2c36.html