Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
- */
- package com.mycompany.validarcuenta;
- /**
- *
- * @author ianto
- */
- import java.util.*;
- public class ValidarCuenta {
- public static void main(String[] args) {
- boolean validarNumeroC;
- String NumeroCuenta = "";
- Scanner entrada = new Scanner (System.in);
- System.out.println("Ingrese su número de cuenta");
- NumeroCuenta = entrada.nextLine();
- validarNumeroC = validarNumeroCuenta(NumeroCuenta);
- while(!validarNumeroC){
- System.out.println("Número de cuenta no valido");
- System.out.println("Ingrese nuevamente el número de cuenta");
- NumeroCuenta = entrada.nextLine();
- validarNumeroC = validarNumeroCuenta(NumeroCuenta);
- }
- System.out.println("Número de cuenta ingresado correctamente");
- }
- public static boolean validarNumeroCuenta(String NumeroCuenta){
- int contador = 0;
- boolean cuentaValida = false;
- if(NumeroCuenta.length() == 28){
- for(int i = 0; i<NumeroCuenta.length(); i++){
- if( i == 0){
- switch(NumeroCuenta.charAt(i)){
- case 'G':
- contador ++;
- break;
- }
- }
- if(i == 1){
- switch(NumeroCuenta.charAt(i)){
- case 'T':
- contador ++;
- break;
- }
- }
- switch(i){
- case 2: case 3:
- switch(NumeroCuenta.charAt(i)){
- case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- contador ++;
- break;
- }
- break;
- case 4: case 5: case 6: case 7:
- switch(NumeroCuenta.charAt(i)){
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
- contador ++;
- break;
- }
- break;
- case 8:
- switch(NumeroCuenta.charAt(i)){
- case '0':
- contador ++;
- break;
- }
- break;
- case 9:
- switch(NumeroCuenta.charAt(i)){
- case '1': case '2':
- contador ++;
- break;
- }
- break;
- case 10:
- switch(NumeroCuenta.charAt(i)){
- case '0':
- contador ++;
- break;
- }
- break;
- case 11:
- switch(NumeroCuenta.charAt(i)){
- case '1': case '2':
- contador ++;
- break;
- }
- break;
- case 12: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26: case 27:
- switch(NumeroCuenta.charAt(i)){
- case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9':
- case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
- contador ++;
- break;
- }
- break;
- }
- }
- }
- if(contador == NumeroCuenta.length()){
- cuentaValida = true;
- }
- return cuentaValida;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement