java实现身份证15位转18位

类别:Java 点击:0 评论:0 推荐:

public static final String getNewId(String id)
 {
 
  final int [] W =
        {
        7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1};
   final String [] A =
   {
        "1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"};
  int i,j,s=0;
  String newid;
   newid = id;
   newid =newid.substring(0,6)+"19"+newid.substring(6,id.length());
   for ( i=0;i<newid.length() ;i++ )
   {

   j= Integer.parseInt(newid.substring(i,i+1))*W[i];
   s=s+j;
   }
   s = s % 11;
   newid=newid+A[s];
 
   return newid;
 
 }

本文地址:http://com.8s8s.com/it/it15873.htm