/
DmitriiSuntsov
/
HW_EXC
Обзор
Документация
Войти
/
DmitriiSuntsov
/
HW_EXC
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PasswordChecker.java
53 строки
2 KB
DmitriiSuntsov
upload files
15 мар 2025, 13:45
15 мар 2025, 13:45
2c96848
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength = -1; private int maxRepeats = -1; public void setMinLength(int minLength) { if (minLength < 0) { throw new IllegalArgumentException("Значение не может быть отрицательным или равным 0"); } 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 == - 1 || maxRepeats == -1) { throw new IllegalStateException("Настройки для чекера не заданы"); } if (password.length() > minLength && charCheck(password) <= maxRepeats) { System.out.println("Подходит!"); return true; } else if ("end".equals(password)) { System.out.println("Программа завершена."); } else { System.out.println("Не подходит!"); } return false; } public int charCheck(String password) { int count = 1; for (int i = 1; i < password.length(); i++) { char previousChar = password.charAt(i - 1); char currentChar = password.charAt(i); if (currentChar == previousChar) { count++; if (count > maxRepeats) { break; } } else if (currentChar != previousChar) { count = 1; } } return count; } }