密码验证合格程序

题目描述:

密码要求:1.长度超过8位。2.包括大小写字母,数字,其它符号,以上四种至少三种。3.不能有相同长度超2的子串重复。

输入描述:一组或多组长度超2的字符串。每组占一行。

输出描述:如果符合要求输出:OK;否则输出NG。

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            String str=sc.next();
            if(cond1(str)&&cond2(str)&&cond3(str)){
                System.out.println("OK");
            }else{
                System.out.println("NG");
            }
        }
        sc.close();
    }
    //长度超过8位
    public static boolean cond1(String str){
        if(str.length()>8){
            return true;
        }
        return false;
    }
    //包括大小写字母、数字、其它符号,至少三种。
    public static boolean cond2(String str){
        int count=0;
        boolean falgnum=false;
        boolean flagsmall=false;
        boolean flagupp=false;
        for(int i=0;i<str.length();i++){
            char c=str.charAt(i);
            if(c>='0'&&c<='9'){
                falgnum=true;
            }
            if(c>='a'&&c<='z'){
                flagsmall=true;
            }
            if(c>='A'&&c<='Z'){
                flagupp=true;
            }
        }
        return (falgnum&&flagsmall)||(falgnum&&flagupp)||(flagsmall&&flagupp);
    }
    //不能有相同的子串重复
    public static boolean cond3(String str){
        for(int i=0;i<str.length()-4;i++){
            String substr=str.substring(i,i+3);
            for(int j=i+1;j<str.length()-4;j++){
                String strsub=str.substring(j,j+3);
                if(substr.equals(strsub)){
                    return false;
                }
            }
        }
        return true;
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值