I have this code:
Scanner sc = null;
sc = new Scanner(System.in);
System.out.println("Your final answer is? (Y/N)");
String answer = sc.next();
if(answer.equals("Y"){
//do sth
}
else if(answer.equals("N")){
//do sth else
}
In case the person does not input “Y” or “N” I want the question to be asked again until the answer is one of those two. Is here a way i can do it?
1 Answer