ID card number conversion program

xiaoxiao2021-03-06  41

Yesterday, I helped my classmates a small program, mainly in order to convert the ID card number from 15 bits into 18. It turned out that when using the subString function, it always passed. Now I have trouble, I haven't seen the original API, now I am listed, and I have reviewed it! The source program is as follows:

Class IDConvert

{Public static void main (String [] ARGS)

{

String T = ""; // 18-digit number, the last value is calculated later

Long R; // The article finally has a comprehensive explanation

String final_id_num;

String ID;

ID = "120103311222265";

LONG N = 0;

String stratailchars = "10x98765432";

Try

{

Long idnum = long.parselong (ID);

IF (id.length ()! = 15)

Throw new Exception ();

}

Catch (IllegalarGumentexception E)

{

System.out.println ("Input is not the correct parameter");

}

Catch (Exception E1)

{

System.out.println ("Enter number bit is incorrect");

}

String id_6_upper = id.substring (0,6); // To add "19" in the original 15-bit number, dismantling two parts

String id_9_lower = id.substring (6,15);

String Original_New_ID = ID_6_UPPER "19" id_9_lower; / / becomes 17-bit number

INT V_LIST [] = {2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7}; // A array of mantissa

INT I, M, REPEAT = 0;

For (i = 0; i <17; i )

{

M = 16-repeat;

//System.out.println(Repeat);

N = long.parselong (Original_New_id.substring (m, m 1)) * (long) v_list [repeat]; // see the tail instruction

//System.out.println (N);

REPEAT ;

}

R = N% 11; // Taking the corresponding T value (18 digits)

System.out.println (r);

FOR (m = 0; M )

{

IF (r == m)

T = strtailchars.substring (m, m 1);

}

System.out.println (t);

Final_id_num = Original_New_ID T; // 17 Bit Number Monil T

System.out.println (Final_ID_NUM);

}

}

The requirements and conversion rules of the program are as follows:

The ID number is converted from 15 to 18. (the input parameters are command line parameters, output 18 ID number) Error handle processing: a. The ID number entered by the user must be 15 bits, if the input is wrong to give prompt. b. If the user enters the non-digital character, give the prompt information. Tip: When the string is converted into a function, the non-digital character is input. Calculate 18 is ID number: ID number 15 to 18-bit conversion algorithm: 1. The ID number is converted from 15 to 18. (The input parameter is the command line parameter) Error handle processing: a. ID number entered by the user Must be 15 bits, if the input is incorrect to give a prompt. b. If the user enters the non-digital character, give the prompt information. Tip: When the string is converted into a function, the non-digital character is input. 1. Insert 2 century code after the 6 administrative regions (such as 19), constitute four birth year, get 17-digit number; 2. Put the 17-bit number from the high to the lower position with the following 17 digits, each multi - : Tip: INT V_LIST [] = {2, 4, 8, 5, 10, 9, 7, 3, 6, 1, 2, 4, 8, 5, 10, 9, 7}; such as: ID number In order to: C1C2C3C4 ... C16C17 n = C17X2 C16X4 ... C1X7; 3. Remove N by 11,000 R, according to the remainder, calculate the mantissa T: 1) If r = 0, T = 1; if r = 2, t = x; 2) If r = 3, t = 9; ... prompt: string stratailchars = "10x98765432"; 4. Add the mantissa T to 17 The 18-digit number is obtained after the number.

The application of the other subString () is as follows:

If there is only one parameter in parentheses,

Return value

The character string object is the string of the character to the tail character with the position of the parameter.

Exp: string aa = '' qWERTY '';

The return value of AA.SUBSTRING (2) is: 'rty' '

If there are two parameters, you can understand this: The first parameter is

The character of the original string corresponds to the parameter, the second parameter is from the original string, and the first character calculates a total of several characters, the return value is between the two parameters corresponding characters. That string

Exp: string aa = '' qwertyuiop ''

The return value of AA.SUBSTRING (2, 8) is: 'rtyui' '

After writing, even if you are dizzy, I hope to remember it, sweat ...

转载请注明原文地址:https://www.9cbs.com/read-77129.html

New Post(0)