-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrong Password Checker II
More file actions
30 lines (25 loc) · 906 Bytes
/
Strong Password Checker II
File metadata and controls
30 lines (25 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class Solution {
public boolean strongPasswordCheckerII(String password) {
int p = password.length();
if(p<8) return false;
boolean lower= false;
boolean upper = false;
boolean digit = false;
boolean special = false;
String specialChar="!@#$%^&*()-+";
for(int i=0;i<p;i++){
if(Character.isLowerCase(password.charAt(i)))
lower = true;
else if(Character.isUpperCase(password.charAt(i)))
upper=true;
else if(Character.isDigit(password.charAt(i)))
digit = true;
else if(specialChar.contains(""+password.charAt(i)))
special=true;
if(i>0){
if(password.charAt(i)==password.charAt(i-1)) return false;
}
}
return lower && upper && digit && special;
}
}