/
ValentinaE
/
Exception
Обзор
Документация
Войти
/
ValentinaE
/
Exception
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PasswordChecker.java
46 строк
1 KB
ValentinaE
upload files
10 фев 2025, 12:56
10 фев 2025, 12:56
dcc3993
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength; private int maxRepeats; private boolean minLengthSet = false; private boolean maxRepeatsSet = false; public void setMinLength(int length) { if (length < 0) { throw new IllegalArgumentException("Минимальная длина пароля не может быть отрицательной"); } this.minLength = length; this.minLengthSet = true; } public void setMaxRepeats(int repeats) { if (repeats <= 0) { throw new IllegalArgumentException("Максимальное количество повторений должно быть положительным числом"); } this.maxRepeats = repeats; this.maxRepeatsSet = true; } public boolean verify(String password) { if (!minLengthSet || !maxRepeatsSet) { throw new IllegalStateException("Не подходит"); } if (password.length() < minLength) { return false; } int repeatCount = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == password.charAt(i - 1)) { repeatCount++; if (repeatCount > maxRepeats) { return false; } } else { repeatCount = 1; } } return true; } }