An if condition gets ignored

Sim :

This bit of the code is supposed to check if the password length is good, butif the password length is greater than or equals 16, it skips the if condition and doesnt print the sentence.

/* This bit of the coe just checks the length of the password */
if (Password.length() >= 8) {
    if (Password.length() <= 10) {
        System.out.println("Medium length of password");
    }
}
else if (Password.length() < 8) {
    System.out.println("Bruv youre asking to be hacked");
} 
else if (i >= 10) {
    if (Password.length() <= 13) {
        System.out.println("Good password length");
    }
    /* The part that fails */
    else if (Password.length() >= 16) {
        System.out.println("Great password length");
    }        
} 

The code should output "Great password length" if the password length is greater than or equal to 16 but it doesnt output anything if it's greater han or equal ot 16

Eran :

if(Password.length() >= 8) and else if(Password.length() < 8) cover all possible password lengths, so the following conditions are never reached.

You should organize your conditions in a less confusing manner:

if (Password.length() < 8) {
    System.out.println("Bruv youre asking to be hacked");
} else if (Password.length() >= 8 && Password.length() <= 10) {
    System.out.println("Medium length of password");
} else if (Password.length() > 10 and Password.length() <= 13) {
    System.out.println("Good password length");
} else if (Password.length() > 13 && Password.length() < 16) {
    ... // you might want to output something for passwords of length between 13 and 16
} else {
    System.out.println("Great password length");
}

or even better

if (Password.length() < 8) {
    System.out.println("Bruv youre asking to be hacked");
} else if (Password.length() <= 10) {
    System.out.println("Medium length of password");
} else if (Password.length() <= 13) {
    System.out.println("Good password length");
} else if (Password.length() < 16) {
    ... // you might want to output something for passwords of length between 13 and 16
} else {
    System.out.println("Great password length");
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=126310&siteId=1