0

When using read() from BufferedReader, when I press enter after typing input, the first input is taken but the next input statement is also executed, before I can type input for the next statement.

char c = (char)br.read();
String S = br.readLine();

If I type a character and press enter, then c stores that character but S stores "" and it does not ask me to input S. It's as if Java automatically presses enter for the string input.

Can someone explain this behaviour?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 4
    `read` reads a single character, but you have typed two, the character and the return character. So the `readLine` reads the return character, which is terminating an empty line. – tgdavies Jul 22 '23 at 06:01
  • In any case there is no duplicate carriage return anywhere in your question. – user207421 Jul 22 '23 at 08:02

0 Answers0