import
java.util.regex.Pattern;
import
java.util.regex.Matcher;
class
GFG {
static
int
countCharacters(
String password)
{
int
count =
0
;
Pattern digit = Pattern.compile(
"(\\d)"
);
Pattern upper = Pattern.compile(
"([A-Z])"
);
Pattern lower = Pattern.compile(
"([a-z])"
);
Pattern spChar = Pattern.compile(
"(\\W)"
);
Matcher Digit = digit.matcher(password);
Matcher Upper = upper.matcher(password);
Matcher Lower = lower.matcher(password);
Matcher Special = spChar.matcher(password);
if
(!Digit.find()) {
count++;
}
if
(!Upper.find()) {
count++;
}
if
(!Lower.find()) {
count++;
}
if
(!Special.find()) {
count++;
}
if
((count + password.length()) <
8
) {
count = count +
8
- (count + password.length());
}
return
count;
}
public
static
void
main(String args[])
{
String password1 =
"Geeksforgeeks"
;
System.out.println(
countCharacters(password1));
String password2 =
"Geeks1"
;
System.out.println(
countCharacters(password2));
}
}