/
h2r
/
Exceptions
Обзор
Документация
Войти
/
h2r
/
Exceptions
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
46 строк
2 KB
h2r
Исключения
08 ноя 2025, 13:52
08 ноя 2025, 13:52
05b69f9
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength; private int maxRepeats; public void setMinLength(int minLength) { if (minLength < 0) { throw new IllegalArgumentException("Минимальная длина не может быть отрицательной"); } this.minLength = minLength; } public void setMaxRepeats(int maxRepeats) { if (maxRepeats <= 0) { throw new IllegalArgumentException("Максимальное количество повторений должно быть больше 0"); } this.maxRepeats = maxRepeats; } public boolean verify(String password) { if (minLength < 0 || maxRepeats <= 0) { throw new IllegalStateException("Настройки minLength и maxRepeats должны быть установлены"); } if (password == null) { throw new IllegalArgumentException("Пароль не может быть null"); } if (password.length() < minLength) { return false; } int count = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == password.charAt(i - 1)) { count++; if (count > maxRepeats) { return false; } } else { count = 1; } } return true; } public void printSettings() { System.out.println("Настройки: минимум длина = " + minLength + ", макс. повторений = " + maxRepeats); } }