Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ValidarCedula {
- public static void main(String[] args) {
- Scanner entrada = new Scanner(System.in);
- String ncedula;
- System.out.println("Ingrese el numero de cedula");
- ncedula=entrada.next();
- int cedula[] = new int[ncedula.length()];
- int res=0;
- if (cedula.length==10)
- {
- for (int i=0;i<cedula.length;i++)
- {
- cedula[i]=Integer.parseInt(String.valueOf(ncedula.charAt(i) ));
- int r=i%2;
- if (r==0)
- {
- cedula[i]=cedula[i]*2;
- if (cedula[i]>9)
- cedula[i]=cedula[i]-9;
- }
- }
- for (int i=0;i<cedula.length-1;i++)
- {
- res=res+cedula[i];
- }
- res=res%10;
- if (res!=0)
- res=10-res;
- if (res==cedula[9])
- System.out.println("CEDULA VALIDA");
- else
- System.out.println("CEDULA INVALIDA");
- }
- else
- System.out.println("CEDULA INVALIDA");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement