-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordValidation.java
More file actions
39 lines (35 loc) · 1.02 KB
/
PasswordValidation.java
File metadata and controls
39 lines (35 loc) · 1.02 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
import java.util.Scanner;
public class PasswordValidation {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String pw = sc.next();
if (pw.length() >= 7 && isNumeric(pw) >= 2 && isSpecial(pw) >= 2) {
System.out.println("Strong");
}else
System.out.println("Weak");
}
public static int isNumeric(String str) {
int resNum = 0;
char[] c = str.toCharArray();
for (int i = 0; i < c.length; i++) {
if (Character.isDigit(c[i]) == true) {
resNum++;
}
}
return resNum;
}
public static int isSpecial(String str) {
int resSpec = 0;
char[] c = str.toCharArray();
String spec = "!@#$%&*";
char[] d = spec.toCharArray();
for (int i = 0; i < c.length; i++) {
for (char x : d) {
if (x == c[i]) {
resSpec++;
}
}
}
return resSpec;
}
}