Created
June 7, 2018 02:29
-
-
Save fabriciofx/c42269f9cbbb6e2573ea801c9ef7537c 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 Cpf { | |
| public static void main(String[] args) { | |
| int[] d = new int[9]; | |
| for(int i = 0; i < d.length; i++) { | |
| d[i] = args[0].charAt(i) - '0'; | |
| } | |
| System.out.println(Arrays.toString(d)); | |
| boolean equals = true; | |
| for (int i = 0; i < d.length - 1; i++) { | |
| equals = equals & (d[i] == d[i + 1]); | |
| } | |
| if (equals) { | |
| System.out.println("CPF Inválido!"); | |
| } else { | |
| int v1 = 0, v2 = 0; | |
| for (int i = 0; i < d.length; i++) { | |
| v1 = v1 + d[i] * (i + 1); | |
| v2 = v2 + d[i] * i; | |
| } | |
| 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