/
zzeebbaa
/
exeption
Обзор
Документация
Войти
/
zzeebbaa
/
exeption
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
53 строки
2 KB
zzeebbaa
upload files
21 май 2025, 00:14
21 май 2025, 00:14
1314ca2
Код
Авторство
О чём код?
package Lesson_12.hm; public class PasswordChecker { private Integer minLength; private Integer maxRepeats; public void setSetMinLength(Integer minLength) { if (minLength < 0) { throw new IllegalArgumentException("Минимальная длина не может быть отрицательной"); } this.minLength = minLength; } public void SetMaxRepeats (Integer maxRepeats) { if (maxRepeats <= 0) { throw new IllegalArgumentException("Максимальное количество повторений должно быть положительным"); } this.maxRepeats = maxRepeats; } public boolean verify(String password) { if(minLength == null || maxRepeats == null) { throw new IllegalArgumentException("Настройки чекера не заданы"); } if (password.length() < minLength) { return false; } int currentRepeats = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == password.charAt(i - 1)) { currentRepeats++; if (currentRepeats > maxRepeats) { return false; } } else { currentRepeats = 1; } } return true; } public void setMinLength(int minLength) { this.minLength = minLength; } public void setMaxRepeats(int maxRepeats) { this.maxRepeats = maxRepeats; } }