gpt4 book ai didi

java - 检查 if 语句中所有条件的最有效方法?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:29:44 24 4
gpt4 key购买 nike

所以我尝试针对多个条件执行此 if 语句,为了使密码符合条件,它应该满足 5 项中的 4 项。我收到一条错误消息

运算符 && 未定义参数类型 boolean, int

注意:错误发生在我的方法底部,(if语句错误)

      public void passRequirments(){


int digit,symbol,upper,lower;
int countDigit, countSymbol,countUpper,countLower;
countDigit = 0;
countSymbol= 0;
countUpper = 0;
countLower = 0;

for (int i = 0; i < passChar.length; i++){
digit = (int)passChar[i] ;
symbol = (int)passChar[i];
upper = (int)passChar[i];
lower = (int)passChar[i];

if(digit >=48 && digit <= 57){
countDigit = 1;
System.out.println(countDigit);
}
else if(symbol >=32 && symbol <= 47 || symbol >=58 && symbol <= 64 ||
symbol >=91 && symbol <= 96 || symbol >=123 && symbol <= 126){
countSymbol = 1;
if (countSymbol == 1){

System.out.println("hello");
}
}
else if( upper >=65 && upper <= 90){
countUpper = 1;
}
else {
countLower = 1;
}

}
//this is where i'm running into error

if(passChar.length >= 8 && countDigit == 1 && countSymbol && countUpper == 1 ||
passChar.length >= 8 && countDigit == 1 && countSymbol && countLower == 1 ||
passChar.length >= 8 && countDigit == 1 && countLower && countUpper == 1 ||
passChar.length >= 8 && countSymbol == 1 && countLower && countUpper == 1){

System.out.println("Password Qualfies!");
passwordScore = passwordScore + 10;

}
else {

System.out.println("Password Doesn't Qualify!");


}


}

最佳答案

在java中,if语句中的参数应该是严格的boolean

我看到您只是在检查 countSymbol 而不是根据您的要求它应该是 countSymbol == 0countSymbol > 0 .

if(passChar.length  >= 8  && countDigit == 1 && countSymbol==0 && countUpper == 1 ||
^ change this

对其他Or条件也做类似的修改

关于java - 检查 if 语句中所有条件的最有效方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43960228/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com