回复:(tibetshu)[求助]根据身份证号码位数如何判断...
package web_service;
public class javaBean1
{
private String code_15;//15位身份证号码
private String code_18;//18位身份证号码
private String sex;//性别
private String birthday;//生日
public javaBean1() {
}
//输入
public void inpt(String code2)
{
//330127860701001
this.code_15=code2;
this.sex=code2.substring(14);
this.birthday=code2.substring(6,8)+"年"+code2.substring(9,10)+"月"+code2.substring(11,12)+"日";
}
public String Exception_()
{
if(this.code_15.length()==15)
{
return "go";
}
else
{
return "error";
}
}
//输出性别
public String outSex()
{
return this.sex;
}
//输出生日
public String outBirthday()
{
return this.birthday;
}
//输出15位身份证号码
public String outCode_15()
{
return this.code_15;
}
//输出18位身份证号码
public String outCode_18()
{
String num_1_6 = code_15.substring(0, 6);
String num_7_15 = code_15.substring(6, code_15.length());
this.code_18 = num_1_6 + "19" + num_7_15;
int newshuzi[] = new int[17];
char[] cha = this.code_18.toCharArray();
try {
for (int i = cha.length; i >0; i--)
{
char s=cha[i-1];
String shuzi = Character.toString(s);
int count = Integer.parseInt(shuzi);
newshuzi[17-i] = count;
}
} catch (NumberFormatException ex)
{
System.out.print(ex.getMessage());
}
int ss[] = new int[] {2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9,
7};
int sh[] = new int[17];
for (int i = 0; i < ss.length; i++)
{
sh[i] = newshuzi[i] * ss[i];
}
int Consd = 0;
for (int i = 0; i < 17; i++)
{
Consd += sh[i];
}
int r = Consd % 11;
String t = "";
if (r == 0) {
t = "1";
}
if (r == 1) {
t = "0";
}
if (r == 2) {
t = "x";
}
if (r == 3) {
t = "9";
}
if (r == 4) {
t = "8";
}
if (r == 5) {
t = "7";
}
if (r == 6) {
t = "6";
}
if (r == 7) {
t = "5";
}
if (r == 8) {
t = "4";
}
if (r == 9) {
t = "3";
}
if (r == 10) {
t = "2";
}
this.code_18 += t;
return this.code_18;
}
}
[此贴子已经被作者于2007-10-21 20:09:17编辑过]