I wrote a for loop like this:
for(int i = 0; (char) System.in.read() != 's'; i++){ System.out.print(i); } I expected the program to keep printing numbers until I type s on the keyboard. However, every time I typed a letter, I got three numbers on the command prompt:
a 012 q 345 There should be only one number printed on the console after each letter typed, but there are three. Why?
System.in.read(), which is buffered and waits until end-of-line.