Why Boolean value doesn't change its value in else snippet, since overriding should happen in keepGoing variable in else body, what is the problem?
import java.util.Scanner;
public class Main {
public static void main(String[] name) {
Scanner display = new Scanner(System.in);
StringBuilder check = new StringBuilder();
boolean keepGoing = false;
do{
System.out.println("please insert your name to check if it is valid or not:");
String Name = display.next();
if(Name.equals("alex")) {
System.out.println("it is valid");
keepGoing = false;
}
else {
System.out.println("it is not valid");
System.out.println("do you want to continue: yes/no");
check.append(display.next());
keepGoing = check.equals("yes");
}
} while(keepGoing);
}
}```
Aucun commentaire:
Enregistrer un commentaire