/
maksh
/
hw10
Обзор
Документация
Войти
/
maksh
/
hw10
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/PasswordChecker.java
54 строки
2 KB
maksh
upload files
14 июн 2025, 11:40
14 июн 2025, 11:40
d1b07f9
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength; private int maxRepeats; public void setMinLength(int minLength) { if (minLength <= 1) { throw new IllegalArgumentException(); } this.minLength = minLength; } public void setMaxRepeats(int maxRepeats) { if (maxRepeats <= 0) { throw new IllegalArgumentException(); } this.maxRepeats = maxRepeats; } public boolean verify(String password) { if (password.length() >= minLength) { if (numberOfChar(password)) { return true; } } return false; } public String getMinLength() { return "Установленная длина пароля: " + minLength; } public String getMaxRepeats() { return "Установленное макс. допустимое количество повторений символа подряд: " + maxRepeats; } private boolean numberOfChar(String password) { int count = 0; for (int i = 0; i < password.length(); i++) { if (count > maxRepeats) { return false; } count = 0; for (int j = i + 1; j < password.length(); j++) { if (password.charAt(i) == password.charAt(j)) { count++; } else { break; } } } return true; } }