-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongPasswordHR.java
More file actions
62 lines (56 loc) · 1.55 KB
/
Copy pathStrongPasswordHR.java
File metadata and controls
62 lines (56 loc) · 1.55 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria:
//Its length is at least 6.
//It contains at least one digit.
//It contains at least one lowercase English character.
//It contains at least one uppercase English character.
//It contains at least one special character. The special characters are: !@#$%^&*()-+
import java.util.Scanner;
public class StrongPasswordHR {
static int minimumNumber(int n, String pass){
boolean upperCase = false;
boolean lowerCase = false;
boolean digit = false;
int count =0;
if(n < 6){
return (6- n);
}
else {
for(int i=0; i<n; i++){
if(Character.isUpperCase(pass.charAt(i))){
upperCase = true;
continue;
}
if(Character.isLowerCase(pass.charAt(i))){
lowerCase = true;
continue;
}
if(Character.isDigit(pass.charAt(i))){
digit = true;
continue;
}
}
if(upperCase != true){
++count;
}
if(lowerCase != true){
++count;
}
if(digit != true){
++count;
}
if(pass.matches(".*[!@#$%^&*()\\-+].*")){
++count;
}
}
return count;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
String password = in.next();
int answer = minimumNumber(n, password);
System.out.println(answer);
in.close();
}
}