zoukankan      html  css  js  c++  java
  • 密码合格验证程序

    package HUAWEI;

    import java.util.Scanner;

    public class Main1_1 {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            StringBuilder builder = new StringBuilder();
            while (scanner.hasNext()) {
                String input = scanner.nextLine();
                System.out.println(passwordValidate(input));
            }
            scanner.close();
     
        }
     
        private static String passwordValidate(String input) {
            final String OK = "OK";
            final String NG = "NG";
     
            // 长度超过8
            if (input == null || input.length() < 9) {
                return NG;
            }
     
            int num1 = 0,num2 = 0,num3 = 0,num4 = 0;
            
     
            // 统计
            for (int i = 0; i < input.length(); i++) {
                char ch = input.charAt(i);
                if (ch >= 'A' && ch <= 'Z') {
                    num1 = 1;
                } else if (ch >= 'a' && ch <= 'z') {
                    num2 = 1;
                } else if (ch >= '0' && ch <= '9') {
                    num3 = 1;
                } else {
                    num4 = 1;
                }
            }
              
            // 小于三种
            if ((num1 + num2 + num3 + num4) < 3) {
                return NG;
            }
     
            System.out.println("字符串的长度:"+input.length());
            for (int i = 0; i < input.length() - 3; i++) {
                String s1 = input.substring(i, i + 3);
                String s2 = input.substring(i + 3, input.length());
                System.out.println("第"+i+"次"+s1+"..."+s2);
                if (s2.contains(s1)) {
                    return NG;
                }
            }
            return OK;
        }
    }

  • 相关阅读:
    原型链的树形结构
    粗略讲一讲js的代码执行机制
    30天前端打卡整理记录
    简单模拟Vue的数据代理功能
    JavaScript语言精粹读后记录
    JavaScript巧用对象的引用解决三级联动
    es6新了解
    记录小程序开发的n个坑
    比拼人品-拼手气红包的JavaScript实现方式.
    一诺千金:微信小程序的wx.request 与Promise的结合使用
  • 原文地址:https://www.cnblogs.com/airycode/p/5120337.html
Copyright © 2011-2022 走看看