you can use regex to filter input
.matches("^[a-pA-P0-9]*$") //this will not allow outside range of [a-p A-P] or numbers
^ Assert position at start of the string
- Create a character range with the adjascent tokens
a-p A single character in the range between a and p (case sensitive)
A-P A single character in the range between A and P (case sensitive)
0-9 A single character in the range between 0 and 9
* Repeat previous token zero to infinite times, as many times as possible
$ Assert position at end of the string
like this:
Scanner input = new Scanner(System.in);
System.out.print("Choose letter in range [a - p]");
letter = input.next().charAt(0);
if (Character.toString(letter).matches("^[a-pA-P0-9]*$")) {
System.out.println("valid input");
}else{
System.out.println("invalid input");
}
SEE REGEX DEMO