title: Java. System.in.read() and "\n" in console
body: <p>Im currently creating a java program which should read the console and print it out, once again. The code looks like this:</p>
  
  <pre><code>import java.io.IOException;
  
  public class printer {
  public static void main(String[] args){
      int i;
      try {
          while ((i = System.in.read()) != -1) {
          char c = (char)i;
  
          System.out.print(c);
  
          }
      }
      catch (IOException e) {
          e.printStackTrace();
      } 
  }
  }
  </code></pre>
  
  <p>The problem is, if you type this text below in the console you will get the first line printed, but since its a <code>"\n"</code> after the word "print" the program doesn't print the second line without me pressing Enter manually </p>
  
  <pre><code>This is the text I want to print
  And now I pressed Enter
  </code></pre>
  
  <p>And when i press enter, to get the second line, the result is:</p>
  
  <pre><code>This is the text I want to print
  
  And now I pressed Enter
  </code></pre>
  
  <p>Which is not how it normally looked like.</p>
  
  <p>I would prefer if the first line didn't print automatically. I want to press Enter and get both lines at the same time. Is that possible using <code>while ((i = System.in.read()) != -1)</code> like I do? </p>