Answer:
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
String response = "";
while (true) {
System.out.print("Enter the response: ");
response = stdin.nextLine();
if (response.equals("Y") || response.equals("y") || response.equals("N") || response.equals("n"))
break;
}
}
}
Explanation:
Create a string variable called response
Create a while loop that iterates until a condition is specified to stop
Inside the loop:
Ask the user for the input
Check if input equals "Y", "y", "N" or "n". If input equals any of these letters, stop the loop. Otherwise, continue asking for a new response