Created
June 7, 2018 02:30
-
-
Save fabriciofx/9e6c22a9ecbb598001673f917b4fe94f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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