I do not know what I'm failing with this Do While

0

Greetings people. I'm starting with Java and doing an exercise testing the do_while I do not know at what point I'm failing. The intention of the loop is that if the user enters a value lower than 1 or higher than 4, the program will ask the user to re-enter the value.

If I leave you like this, when you enter a correct value you should ask again to enter the number but, as it seems, the loop is cut off.

The point is that I've tried and if I just leave a condition in while it works fine for me but when I put the & & amp; Something fails me.

Am I failing in something or is it that the while can not contain multiple conditions?

Thanks in advance.

public class Act6_4 {

public static void main(String[] args) {
    //Declaración de variables
    int estacion=50;

    Scanner teclado = new Scanner (System.in);

    //Empieza el bucle por si el usuario introduce un número fuera del rango de opciones
    do { 
        //Muestra mensaje en pantalla pidiendo al usuario que introduzca un número del 1 al 4
        System.out.println("Introduce número de estación (1 al 4)");
        estacion = teclado.nextInt();

        //Empieza la condición con varias opciones
        switch (estacion) {
            case 1: System.out.println("Verano");
                    break;
            case 2: System.out.println("Otoño");
                    break;  
            case 3: System.out.println("Invierno");
                    break;  
            case 4: System.out.println("Primavera");
                    break;  
        }
    }   while (estacion<=0 && estacion>=5);
}

}

    
asked by Vulkaj 29.11.2017 в 21:25
source

1 answer

0

You just have to change this line:

while (estacion>0 && estacion<5);

and each time the value you enter this between 0 and 5 will continue to perform the iteration but when it is different it will end the same.

    
answered by 29.11.2017 в 22:19