dimanche 20 octobre 2019

How to return something when ALL 3 conditions MUST be met in an if statement

A weak password is defined as a password with less than eight characters. A medium password is defined as a password having a length of eight or more characters and having either a digit or an “other” character. A strong password is defined as a password having a length of eight or more characters and having both a digit and an “other” character.

How can I return something when ALL 3 conditions MUST be met? My weak pass is the only thing printing right.

public String test() {
    if (length < 8)
       return weak pass;
    if ((length <=8) || (length <=8 && digit) || (digit <=8 && other))
       return medium pass;
    if (length <= 8 && digit && other)
       return strong pass;
    return null;
}

Aucun commentaire:

Enregistrer un commentaire