System.in.read()
is used to read a single character.
Then why does it allow the user to enter as many characters as he can until he presses enter?
Why doesn't it stop as soon as he presses a key and returns the character?
char ch = (char)System.in.read();
If the user enter "example" and then press enter, It takes the ch
as e
. and discards the other characters.
If there are multiple read()
, it messes the whole thing.
So, why doesn't it take only the single character and then return?