密码问题

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

public class Main {
  public static void main(String[] args) {
      Scanner sc = new Scanner ( System.in );
      String s=null;
      while (sc.hasNext ()) {
          s = sc.nextLine ( );

          if (s.length ( ) < 8 || s == null) {
              System.out.println ( "NG" );
          } else {
              isTrue ( s );
          }
      }
  }
  public static  void isTrue(String s){
      if(isLengthTrue ( s )&&isContentQualified ( s )&&checkCharRepeat ( s )){
          System.out.println ("OK" );
      }
     else{
          System.out.println ("NG" );
      }
}
    // 1.判断长度
public  static  boolean isLengthTrue(String s){
      return s.length ()>8;
}
   //2.判断是否包含大小写,字母以及数字等
public static boolean isContentQualified(String s){
      int Digit=0 , lowercase=0,uppercase=0,others=0;
    char[] ch = s.toCharArray();
    for (int i = 0; i < ch.length; i++) {
        if (ch[i]>='0'&&ch[i]<='9') {
            Digit=1;
            continue;
        }
        else if (ch[i]>='a'&&ch[i]<='z') {
            lowercase=1;
            continue;
        }
        else if (ch[i]>='A'&&ch[i]<='Z') {
            uppercase=1;
            continue;
        }else {
            others=1;
            continue;
        }
    }
    int total = Digit+lowercase+uppercase+others;
    return total>=3 ? true : false;
}
     //3.不能有相同长度超过二的两个字串
    public static boolean checkCharRepeat(String s){
        for(int i=0 ;i<s.length()-2 ;i++){
            String substr1 =s.substring(i, i+3);
            if (s.substring(i+1).contains(substr1)) return false;
        }
        return true;
    }
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值