title: How to read a line which doesn't end with new line or carriage return character in java?
body: <p>I am using BufferedReader as follows,</p>
  
  <pre><code>BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  for (int i = 0; i &lt; 4; i++) {
     System.out.println(stdin.readLine());
  }
  </code></pre>
  
  <p>And the input given is as follows,</p>
  
  <pre><code>1
  2
  3
  </code></pre>
  
  <p>The last input doesn't end with <code>\n</code> or <code>\r</code>,  therefore for 3 readLine() will expect input from user unless user presses enter key</p>
  
  <p>Any solution for this using Scanner ?</p>
  
  <p>Actually, I got into this problem while solving , <a href="http://www.quora.com/challenges#nearby" rel="nofollow noreferrer">Quora Question Nearby</a>, In their <a href="https://www.interviewstreet.com/recruit/challenges/faq/view#trailing" rel="nofollow noreferrer">conditions</a> they have mentioned following lines,</p>
  
  <p>Does the last line in the input test case end with a newline? [link]</p>
  
  <p>Nope. No trailing spaces or newlines.</p>
  
  <hr>
  
  <p><a href="https://github.com/pradeephrish/quorachallenges/blob/master/Solution.java" rel="nofollow noreferrer">Link for Code</a>, Submitted at above page, test cases are failing </p>
  
  <p>For Test Case Zero, It shows following output ,
  <img src="https://i.stack.imgur.com/fN32z.png" alt="enter image description here">
  Since, expected output is blank, it means my codes still expects <code>\n or \r</code> which is not provided by input</p>