java小白解法
密码验证合格程序
http://www.nowcoder.com/questionTerminal/184edec193864f0985ad2684fbc86841
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
while(sc.hasNext()){
String pass=sc.next();
int count=0;
//判断长度
if(pass.length()<9){
System.out.println("NG");
count++;
}
//判断是否有相同长度大于2的子串重复
if(count==0) {
Loop:for(int i=0;i<pass.length()-5;i++) {
String str=pass.substring(i,i+3);
for (int j=i+3;j<pass.length()-2;j++) {
if (str.equals(pass.substring(j, j+3))) {
System.out.println("NG");
count++;
break Loop;
}
}
}
}
//判断是否包括大小写字母.数字.其它符号,以上四种至少三种
if(count==0) {
char[] P=pass.toCharArray();
boolean a=false;
boolean A=false;
boolean n=false;
boolean fu=false;
for (int i=0;i<P.length;i++) {
if(P[i]>='a'&&P[i]<='z') {
a=true;
}
else if(P[i]>='A'&&P[i]<='Z') {
A=true;
}
else if(P[i]>='0'&&P[i]<='9') {
n=true;
}
else{
fu=true;
}
}
if(!((A&&a&&n)||(A&&a&&fu)||(A&&n&&fu)||(a&&n&&fu))) {
System.out.println("NG");
count++;
}
}
\\所有条件都符合输出OK
if(count==0) {
System.out.println("OK");
}
}
}
}
深信服公司福利 789人发布