题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String pwd = in.nextLine();
            int size = pwd.trim().length();
            if (size < 8) {
                System.out.println("NG");
                return;
            }
            char[]cs = pwd.toCharArray();
            int count = 0;
            boolean ngChar = false;
            for (char c : cs) {
                if (c == ' ' || c == '\n') {
                    ngChar = true;
                    break;
                }
                if (c >= 'a' && c <= 'z') {
                    count++;
                } else if (c >= 'A' && c <= 'Z') {
                    count++;
                } else if (c >= '0' && c <= '9') {
                    count++;
                } else {
                    count++;
                }
            }
            if (ngChar) {
                System.out.println("NG");
                return;
            }
            if (count < 3) {
                System.out.println("NG");
                return;
            }
            if (!reStr(pwd)) {
                System.out.println("NG");
                return;
            }
            System.out.println("OK");
        }
    }
    private static boolean reStr(String s) {
        for (int i = 3; i < s.length(); i++) {
            if (s.substring(i).contains(s.substring(i - 3, i))) {
                return false;
            }
        }
        return true;
    }

}

我不理解为啥会报错,蹲个大神指津下!

#悬赏#
全部评论

相关推荐

下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务