How can I do a try catch and repeat the option I am doing?

2
System.out.println("Ingrese tipo de cuenta  \n1. corriente\n2.Ahorro");
tipo=Integer.parseInt(entrada.readLine());//-->>

How could I do that for example here you have to enter a number but if you enter with a letter that the try catch would be the Numberformat but to repeat the option enter as could i do it?

    
asked by Enrique 10.08.2018 в 15:03
source

1 answer

1

Reading what you need I have implemented a cycle with a try catch in which you will do it until it is a number.

boolean resultado;
int tipo;
 do
 {

   System.out.println("Ingrese tipo de cuenta  \n1. corriente\n2.Ahorro");

   try {
            tipo=Integer.parseInt(entrada.readLine());
            resultado = true;
        } catch (NumberFormatException excepcion) {
            resultado = false;
        }
 }
 while (!resultado);

I hope you serve and marques xD ... ReNiceCode ...

    
answered by 10.08.2018 в 15:16