What is the error of this code - java

0
Genero obj=new Genero();
    int swG=0;
    while(swG==0) {
    System.out.print("Genero\nM : Masculino\nF : Femenino\n>>");
    obj.setTipoGenero(entrada.next().charAt(0));

       if ((obj.getTipoGenero() != 'm') || (obj.getTipoGenero() != 'M') || 
            (obj.getTipoGenero() != 'f') || (obj.getTipoGenero() != 'F')) {

            System.out.println("Seleccione la opcion correcta ");

        }else {
                swG=1;
        }
     }

My intention for the following fragment of code is that it captures a char either M or F according to the case and if it is different from 'm' or 'M' or 'f' or 'F' I will ask again since it is not the correct one for which it is the cycle and if it is correct then the swG is ignited and it leaves the cycle and follows with the flow of the code, that happens with the code?

    
asked by MZ39720 23.06.2018 в 08:50
source

1 answer

0

The condition is poorly written. It should be like this:

 if ((obj != 'm' && obj != 'M') && 
        (obj != 'f' && obj != 'F'))

With this, what you do is check in groups, first check if it is m or M and then if it is f or F.

    
answered by 23.06.2018 / 09:02
source