1、 校验长度
2、 校验字符种类
3、 校验子串是否有大于2的
import java.util.*;
public class Main{
public static void main(String [] args){
testPassword();
}
public static void testPassword(){
Scanner scan = new Scanner(System.in);
while(scan.hasNext()){
String password = scan.nextLine();
int len = password.length();
// 校验长度
if(len < 9){
System.out.println("NG");
continue;
}
// 校验字符种类
Set<String> set = new HashSet<>();
for(int i = 0; i <len; i++){
char ch = password.charAt(i);
if('a' <= ch && ch<='z'){
set.add("flag1");
}else if('A' <= ch && ch<='Z'){
set.add("flag2");
}else if('0' <= ch && ch<='9'){
set.add("flag3");
}else{
set.add("flag4");
}
if(set.size() >= 3){
break;
}
}
if(set.size() < 3){
System.out.println("NG");
continue;
}
// 校验子串是否有大于2的
String str = "";
int l=0;
int r =3;
boolean falg = false;
while(r <= len){
str = password.substring(l,r);
String temp = password.substring(r);
if(temp.contains(str)){
falg = true;
break;
}
l++;
r++;
}
if(falg){
System.out.println("NG");
}else{
System.out.println("OK");
}
}
}
}

京公网安备 11010502036488号