/
Pavel23
/
HW12
Обзор
Документация
Войти
/
Pavel23
/
HW12
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
32 строки
1 KB
Pavel23
upload files
09 ноя 2025, 14:33
09 ноя 2025, 14:33
c943e41
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength = -1; private int maxRepeats = -1; public void setMinLength(int minLength) { if (minLength < 0) { throw new IllegalArgumentException("Недопустимая длина: " + minLength); } this.minLength = minLength; } public void setMaxRepeats(int maxRepeats) { if (maxRepeats <= 0) { throw new IllegalArgumentException("Недопустимое количество повторов: " + maxRepeats); } this.maxRepeats = maxRepeats; } public boolean verify(String password) { if (minLength == -1 || maxRepeats == -1) { throw new IllegalStateException("Недопустимое состояние: одна из настроек не была установлена"); } int repeats = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == password.charAt(i - 1)) { repeats++; if (repeats > maxRepeats) return false; } else repeats = 1; } return password.length() >= minLength; } }