Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CINUtil {
- public static String computeCin(String abi, String cab, String conto) {
- String result = null;
- String NUMERI = "0123456789";
- String LETTERE = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- int DIVISORE = 26;
- int somma = 0;
- int[] aListaPari = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25};
- int[] aListaDispari = new int[]{1, 0, 5, 7, 9, 13, 15, 17, 19, 21, 2, 4, 18, 20, 11, 3, 6, 8, 12, 14, 16, 10, 22, 25, 24, 23};
- String strAbiCabConto = abi + cab + conto;
- String strChar = "";
- int i = 0;
- for (int k = 1; k <= 22; k++) {
- strChar = strAbiCabConto.substring(k - 1, k);
- i = NUMERI.indexOf(strChar);
- if (i < 0) {
- i = LETTERE.indexOf(strChar);
- }
- i++;
- somma = somma + (k % 2 == 0 ? aListaPari[i - 1] : aListaDispari[i - 1]);
- }
- int y = 1 + (somma % DIVISORE);
- result = LETTERE.substring(y - 1, y);
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement