I want to make the user enter only "y" "Y" "n" or "N". The resulting code asks the user to enter Y or N when they have entered the correct input, the opposite of what I expected by placing the ! in front of input.equalscaseignore(input).
import java.util.Scanner;
class inputVal {
public static void main(String[] args) {
String Input;
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter Y or N. ");
Input = keyboard.nextLine();
while (!Input.equalsIgnoreCase("Y") || !Input.equalsIgnoreCase("N"))
{
System.out.println("Please enter Y or N");
Input = keyboard.nextLine();
}
keyboard.close();
}
}