搜档网
当前位置:搜档网 › 新旧身份证的转换

新旧身份证的转换

新旧身份证的转换.txt恨一个人和爱一个人的区别是:一个放在嘴边,一个藏在心里。人生三愿:一是吃得下饭,二是睡得着觉,三是笑得出来。回答人的补充 2009-10-29 19:03 //最后3位(18位身份证最后4位),是序号,表示办理身份证的第几名,
//其中性别在最后一位表示(18位身份证在倒数第二位),奇数是男性,偶数是女性.
import java.util.*;

public class IdentityNumber {

public static void main(String[] args) {

Scanner stdIn = new Scanner(System.in);
String input = stdIn.nextLine();
int length = input.length();
for (int i = 0; i < length; i++) {

char c = input.charAt(i);
if (i != 17 && (c < '0' || c > '9')
|| i == 17 && !(c >= '0' && c <= '9' || c == 'x' || c == 'X')) {

System.out.println("输入格式不正确!");
System.exit(0);
}
}
if (length == 18) {

System.out.println("此号码是新号码。");
} else if (length == 15) {

input = input.substring(0, 6) + 19 + input.substring(6, 15);
System.out.print("此号码是旧号码。转化为新号码为:");
int[] weights = {7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2};
int checksum = 0;
for (int i = 0; i < 17; i++) {

checksum += (input.charAt(i) - '0') * weights[i];
}
checksum %= 11;
if (checksum < 2) {

checksum = 1 - checksum;
} else {

checksum = 12 - checksum;
}
input += checksum < 10 ? checksum : "X";
System.out.println(input);
} else {

System.out.println("输入格式不正确!");
System.exit(0);
}
System.out.println("生日为:" + input.substring(6, 10) + "年"
+ input.substring(10, 12) + "月" + input.substring(12, 14) + "日");
System.out.println("性别为:" + ((input.charAt(16) - '0') % 2 == 1 ? "男" : "女"));
}
}





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)https://www.sodocs.net/doc/e87042396.html,[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();
}

}





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)https://www.sodocs.net/doc/e87042396.html,[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();
}

}

相关主题