所以我試圖做到這一點,如果聲明多個條件,其中爲了使密碼合格,它應該滿足5件事情中的4件。我得到一個錯誤說最有效的方法來檢查if語句中的所有條件?
操作& &未定義的參數類型布爾,詮釋
注:發生錯誤,在我的方法的底部,(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!");
}
}
你'&& countSymbol'和'&& countLower',這些都是'int's類似的符號會工作。你不能在'int's上執行'&&',只能在'boolean's上執行。 – user1803551
什麼?我不明白 –
'countLower == 1'是一個'boolean' - 無論是'true'還是'false'。 'countLower'是一個'int' - 一個數字。 '&&'之間的東西需要是布爾型的。 – user1803551