The code below is from: Take a char input from the Scanner
char c = reader.next(".").charAt(0);
Why does this take in strictly one character? Any references where I can read about the purpose of the "."?
The code below is from: Take a char input from the Scanner
char c = reader.next(".").charAt(0);
Why does this take in strictly one character? Any references where I can read about the purpose of the "."?
The character .
reffers a Regular Expression (Regex) that means any character.
As you can find in the documentation of Pattern.
Predefined character classes
. Any character (may or may not match line terminators)
Regular Expression is a way to find, match text with some predefined Pattern. If you want to find the next A
ou B
letter, you should use:
char c = reader.next("[AB]").charAt(0);
Take a look at the Pattern documentation to learn better how to use this API.