import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner entrada = new Scanner(System.in);
System.out.println("Crie sua senha: \n" +
"* Deve ter pelo menos 8 caracteres\n" +
"* Deve ter pelo menos um número\n" +
"Senha: ");
String senha = entrada.nextLine();
try {
if ( (int)senha.length() < 8 || senha.matches("[a-z]*")){
throw new ErroSenhaInvalidaException(" Senha não atende aos requisitos. Tente novamente");
}
System.out.println("Senha criada com sucesso!");
} catch (ErroSenhaInvalidaException e) {
System.out.println("Erro!" + e.getMessage());
}
}
//classe erro
public class ErroSenhaInvalidaException extends RuntimeException{
public ErroSenhaInvalidaException(String mensagem){
super(mensagem);
}