Created
October 30, 2019 22:59
-
-
Save MrDave1999/b395823c6fdb51026893418a340572e0 to your computer and use it in GitHub Desktop.
Algoritmo (en Java) para detectar si una cedula Ecuatoriana es válida o no.
This file contains 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.io.*; | |
class Program | |
{ | |
static int toInt(String c, int index) | |
{ | |
return c.charAt(index) - '0'; | |
} | |
public static void main(String arg[]) | |
{ | |
String txt = arg[0]; | |
int digitV = toInt(txt, 9); //digito verificador. | |
int num; | |
int tot = 0; | |
int digit; | |
boolean r = false; | |
int len = txt.length() - 1; | |
for(int i = 0; i != len; ++i) | |
{ | |
num = (r = (!r ? true : false)) ? (2) : (1); | |
tot += ((digit = (toInt(txt, i) * num)) > 9 ) ? (digit - 9) : (digit); | |
} | |
System.out.println( ((((tot % 10 == 0) && (digitV == 0)) || ((10 - (tot % 10)) == digitV))) ? "La cedula es valida\n" : "La cedula no es valida"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment