-2
I am learning Java and decided to make a simple program of login, but I wanted that when the password went wrong he asked again to put the password but I do not know how to do. Can someone help me?
public class PasswordVer {
public static void main(String[] args){
Scanner password = new Scanner(System.in);
String senha1;
String senha2;
System.out.println("Por favor crie uma nova senha:");
senha1 = password.nextLine();
System.out.println("Insira novamente a senha para login:");
senha2 = password.nextLine();
if(senha2.equals(senha1)){
System.out.println("Você agora está logado.");
}else{
System.out.println("Senha incorreta. Por favor tente novamente.");
}
}
}
@Solkarped, from what I understand the guy wants to use a
do..while
orwhile
.– Danizavtz