在后台经常会遇到的密码处理,写一个博客记录一下,主要是用到了String.matches的字符串对比
//密码处理
import java.util.Scanner;
public class Practice1162 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int hang = sc.nextInt();
for (int i = 0; i < hang; i++) {
String password = sc.next();
int safelevel = 0; //安全级别
int length = password.length();
if ( length > 16 || length < 8)
System.out.println("NO");
else {
int moshi = 0;
if (password.matches("(.*)[A-Z](.*)")) { //字符串中有A-Z
safelevel++;
}
if (password.matches("(.*)[a-z](.*)")) { //字符串中a-z
safelevel++;
}
if (password.matches("(.*)[0-9](.*)")) { //字符串中含有0-9
safelevel++;
}
if (password.matches("(.*)[~!@#$%^](.*)")) { //字符串含有~!@#$%^
safelevel++;
}
if (safelevel >= 3) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}
}