Skip to content

Instantly share code, notes, and snippets.

@fabriciofx
Created June 7, 2018 02:30
Show Gist options
  • Select an option

  • Save fabriciofx/9e6c22a9ecbb598001673f917b4fe94f to your computer and use it in GitHub Desktop.

Select an option

Save fabriciofx/9e6c22a9ecbb598001673f917b4fe94f to your computer and use it in GitHub Desktop.
import java.util.Arrays;
public class Cnpj {
public static void main(String[] args) {
int[] d = new int[12];
for(int i = 0; i < d.length; i++) {
d[i] = args[0].charAt(i) - '0';
}
System.out.println(Arrays.toString(d));
int v1 = 0, v2 = 0;
int n1 = 6, n2 = 5;
for (int i = 0; i < d.length; i++) {
if (i == 4) n1 = 2;
if (i == 5) n2 = 2;
v1 = v1 + d[i] * n1++;
v2 = v2 + d[i] * n2++;
}
v1 = (v1 % 11) % 10;
v2 = v2 + v1 * 9;
v2 = (v2 % 11) % 10;
System.out.println("V1: " + v1 + " V2: " + v2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment