while (true) {
String password = "carrot";
String inputtedPassword = reader.nextLine();
System.out.println("Type the password:");
if (password.equals(inputtedPassword)) {
System.out.println("Right!");
} else {
System.out.println("Wrong!");
}
if (password.equals(inputtedPassword)) {
break;
}
}
I'm doing an excercise that asks for a code that keeps asking for the correct "password" until it is given correctly, then it can stop asking. This is the code that I wrote and when I execute it it does what it should, but when I submit it I get an error message that says "Program should keep asking the password until it is given correctly". I am confused.
Aucun commentaire:
Enregistrer un commentaire