-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo19.java
60 lines (57 loc) · 1.32 KB
/
Demo19.java
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
package HUAWEI;
import java.util.Scanner;
public class Demo19 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
String password= sc.nextLine();
if(checkLen(password)&&checkCharKinds(password)){
System.out.println("OK");
}else{
System.out.println("NG");
}
}
}
//判断长度
public static boolean checkLen(String password){
if(password.equals(null)||password.length()<=8){
return false;
}
return true;
}
//判断是否包括大小写数字,其他符号
//遍历字符串的每一个元素,以此判断
public static boolean checkCharKinds(String password){
int upper=0,low=0,digit=0,other=0;
char[] ch=password.toCharArray();
for(int i=0;i<password.length();i++){
if(Character.isUpperCase(ch[i])){
upper=1;
continue;
}else if(Character.isLowerCase(ch[i])){
low=1;
continue;
}else if(Character.isDigit(ch[i])){
digit=1;
continue;
}else{
other=1;
continue;
}
}
if((upper+low+digit+other)>=3)
return true;
return false;
}
//不能有相同长度超过2的字符串
public static boolean checkCharRepeat(String password){
for(int i=0;i<password.length()-2;i++){
String str=password.substring(i, i+3);
for(int j=i+1;j<password.length()-2;j++){
if(password.substring(j).contains(str))
return false;
}
}
return true;
}
}