This repository was archived by the owner on Mar 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongPassword2.java
More file actions
66 lines (48 loc) · 1.81 KB
/
Copy pathStrongPassword2.java
File metadata and controls
66 lines (48 loc) · 1.81 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
63
64
65
66
package day28_ArrayList;
public class StrongPassword2 {
public static void main(String[] args) {
String password = "WoodenSpoon123";
int countUpperCase = 0;
int countLowerCase = 0;
int countDigits = 0;
int countSpecialChar = 0;
for (int i = 0; i < password.length(); i++) {
char each = password.charAt(i);
if(Character.isUpperCase(each)){
countUpperCase++;
}else if(Character.isLowerCase(each)){
countLowerCase++;
}else if(Character.isDigit(each)){
countDigits++;
}else{
countSpecialChar++;
}
}
/*
System.out.println("countLowerCase = " + countLowerCase);
System.out.println("countUpperCase = " + countUpperCase);
System.out.println("countSpecialChar = " + countSpecialChar);
System.out.println("countDigits = " + countDigits);
*/
boolean hasUpperCase = countUpperCase > 0;
boolean hasLowercase = countLowerCase > 0;
boolean hasDigit = countDigits > 0;
boolean hasSpecialChar = countSpecialChar > 0;
// boolean strongPassword = password.length() >= 8 && !password.contains(" ") && hasSpecialChar && hasLowercase && hasUpperCase && hasDigit;
boolean strongPassword =false;
if(password.length() >= 8){
if(!password.contains(" ")){
if(hasUpperCase){
if(hasLowercase){
if(hasDigit){
if(hasSpecialChar){
strongPassword = true;
}
}
}
}
}
}
System.out.println("strongPassword = " + strongPassword);
}
}