Advertisement
robeeeert

ValidarCui

May 25th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1. /*
  2.  * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
  3.  */
  4.  
  5. package com.mycompany.validarcui;
  6.  
  7. /**
  8.  *
  9.  * @author ianto
  10.  */
  11. import java.util.*;
  12. public class ValidarCui {
  13.  
  14.     public static void main(String[] args) {
  15.         String cui;
  16.         String cuatroDigitos;
  17.         boolean cuiValidoo;
  18.         Scanner entrada = new Scanner(System.in);
  19.         /**do{
  20.             System.out.println("Ingrese el número de cui");
  21.             cui = entrada.nextLine();
  22.         }while(!ValidarCui(cui));**/
  23.         System.out.println("Ingrese su número de cui");
  24.         cui = entrada.nextLine();
  25.         cuiValidoo = ValidarCui(cui);
  26.         while(!cuiValidoo){
  27.             System.out.println("Número de cui no valido");
  28.             System.out.println("Ingrese nuevamente el número de cui");
  29.             cui = entrada.nextLine();
  30.             cuiValidoo = ValidarCui(cui);
  31.         }
  32.         System.out.println("Número de cui ingresado correctamente");
  33.     }
  34.     public static boolean ValidarCui(String cui){
  35.         int contadorDigitos = 0;
  36.         boolean cuiValido = false;
  37.        
  38.         if(cui.length()== 13){
  39.             for(int i = 0; i < cui.length(); i++){
  40.                 if(i == 0){
  41.                     switch(cui.charAt(i)){
  42.                         case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
  43.                             contadorDigitos ++;
  44.                             break;
  45.                     }
  46.                    
  47.                 }
  48.                 switch(i){
  49.                     case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12:
  50.                         switch(cui.charAt(i)){
  51.                             case '0':case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
  52.                                 contadorDigitos++;
  53.                                 break;
  54.                         }
  55.                 }
  56.             }  
  57.         }
  58.         if(contadorDigitos == cui.length()){
  59.             cuiValido = true;
  60.         }
  61.         return cuiValido;
  62.     }    
  63. }
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement