Because when you type a and hit Enter, then the in.read() method returns three characters - 'a', the character for carriage return \r and the character for line break ('\n'). (Note that the combination \r\n is considered as line-break under Windows).
Your program will have significantly different behavior if you run it under Linux or OSX, because line-breaking character(s) is specific to the OS you're running the program on. Under Linux, it will be \n, under OS X-9 it will be \r, for example.
As a work-around, you can read the whole line (by using a Scanner) and trim it, which will omit the line-breaking character (disregarding the OS type):
public static void main (String args[]) throws java.io.IOException {
String line;
Scanner sc = new Scanner(System.in);
do {
System.out.println("Please a key followed by ENTER:");
line = sc.readLine().trim();
} while (!"q".equals(line));
}
I assume what gets read as input is containing your ENTER keypress. Since you are on Windows, this includes the CRFL line ending.
Thus, each time you entered your char, you actually input 3 chars. For your first input:
- a
- CR
- LF
Try reading a full line via a BufferedReader and run a whitespace trim on that, or just evaluate its first char.