![](/img/trans.png)
[英]Most efficient way to check if all given n objects are the same or distinct?
[英]Most efficient way to check all conditions in if statement?
所以我試圖這樣做,如果多個條件的聲明,為了使密碼合格,它應該滿足5個中的4個。 我收到一個錯誤說
對於參數類型boolean,int,運算符&&未定義
注意:錯誤發生在我的方法的底部,(如果語句錯誤)
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 == 0
或countSymbol > 0
。
if(passChar.length >= 8 && countDigit == 1 && countSymbol==0 && countUpper == 1 ||
^ change this
在其他Or
條件中也進行類似的更改
如果通過countSymbol && countUpper == 1
你試圖說countSymbol
和 countUpper都應該等於1,那不是&&
如何工作。 您必須完整地寫出兩個條件: countSymbol == 1 && countUpper == 1
。 與countLower && countUpper == 1
。
有趣的事實:如果你用COBOL寫的話,一個類似的表示法會有用:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.