Advertisement
CodeWar

Validar Cedula en Java

Dec 16th, 2012
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.78 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ValidarCedula {
  3.  
  4. public static void main(String[] args) {
  5.  
  6. Scanner entrada = new Scanner(System.in);
  7. String ncedula;
  8. System.out.println("Ingrese el numero de cedula");
  9. ncedula=entrada.next();
  10.  
  11. int cedula[] = new int[ncedula.length()];
  12. int res=0;
  13.  
  14. if (cedula.length==10)
  15. {
  16. for (int i=0;i<cedula.length;i++)
  17. {
  18. cedula[i]=Integer.parseInt(String.valueOf(ncedula.charAt(i) ));
  19. int r=i%2;
  20.  
  21. if (r==0)
  22. {
  23. cedula[i]=cedula[i]*2;
  24. if (cedula[i]>9)
  25. cedula[i]=cedula[i]-9;
  26. }
  27.  
  28. }
  29.  
  30. for (int i=0;i<cedula.length-1;i++)
  31. {
  32. res=res+cedula[i];
  33. }
  34.  
  35. res=res%10;
  36.  
  37. if (res!=0)
  38. res=10-res;
  39.  
  40. if (res==cedula[9])
  41. System.out.println("CEDULA VALIDA");
  42. else
  43. System.out.println("CEDULA INVALIDA");
  44. }
  45. else
  46. System.out.println("CEDULA INVALIDA");
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement