2 回答
TA贡献1898条经验 获得超8个赞
if(Password.length() >= 8)并else if(Password.length() < 8)覆盖所有可能的密码长度,因此永远不会达到以下条件。
你应该以一种不那么混乱的方式组织你的条件:
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");
}
甚至更好
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");
}
TA贡献1844条经验 获得超8个赞
尝试使用:
if (Password.length() >= 8) {
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) {
System.out.println("Great password length");
}
} else if (Password.length() < 8) {
System.out.println("Bruv youre asking to be hacked");
}
添加回答
举报