-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordValidator2
More file actions
25 lines (25 loc) · 854 Bytes
/
PasswordValidator2
File metadata and controls
25 lines (25 loc) · 854 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
/*Write a program that takes in a string as input and evaluates it as a valid password. The password is valid if it has at a minimum 2 numbers, 2 of the following special
characters ('!', '@', '#', '$', '%', '&', '*'), and a length of at least 7 characters.
If the password passes the check, output 'Strong', else output 'Weak'.
*/
import java.util.*;
public class PasswordValidator2{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
int spec = 0,num = 0;
String spec2 = "!@#$%&*";
for (int i=0;i<str.length() ;i++ ) {
if (spec2.contains(Character.toString(str.charAt(i)))) {
spec++;
}else if (Character.isDigit(str.charAt(i))) {
num++;
}
}
if ((str.length()>=7&&spec>=2)&&num>=2) {
System.out.println("Strong");
}else{
System.out.println("Weak");
}
}
}