title: Why multiple nextInt() works?
body: <p>In the following Java code</p>
  <pre><code>Scanner input = new Scanner(System.in);    //Cmd1
  int i1,i2;                                 //Cmd2
  i1 = input.nextInt();                      //Cmd3
  System.out.println(&quot;value of i1 is &quot;+ i1); //Cmd4
  i2 = input.nextInt();                      //Cmd5
  System.out.println(&quot;value of i2 is &quot;+ i2); //Cmd6
  String s1;                                 //Cmd7
  input.nextLine();                          //Cmd8
  s1 = input.nextLine();                     //Cmd9
  System.out.println(&quot;value of s1 is &quot;+ s1); //Cmd10
  </code></pre>
  <p>I got the following output in my console</p>
  <pre><code>&lt;myinput&gt; 1
  &lt;output&gt;  value of i1 is 1
  &lt;myinput&gt; 2
  &lt;output&gt;  value of i2 is 2
  &lt;myinput&gt; firstString
  &lt;output&gt;  value of s1 is firstString
  </code></pre>
  <p>&lt;myinput&gt; kept on waiting for input till i pressed <code>enter</code> key. I tried <code>tab</code>, multiple <code>tab</code>, <code>space</code> but it kept on waiting and didn't move to the next command which is &lt;output&gt; hence i assumed that nextInt waits till it find \n in an input stream before moving onto next command.</p>
  <p>Looking at the answers from <a href="https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo">Scanner is skipping nextLine() after using next() or nextFoo()?</a>, the reason we have to add <code>Cmd8</code> is because nextInt() keep on reading input till <code>\n</code>, sends input to program and puts <code>\n</code> back in front of input stream. Now when nextLine() in &quot;Cmd8&quot; starts reading it, it finds <code>\n</code> at the starting of input stream without any preceding string, it assumes user didn't enter anything hence takes empty string as input and go to <code>Cmd9</code>. <br/><br/> My doubt here is since nextInt() also reads till <code>\n</code> (implying from my experience that <code>Cmd3</code> kept on waiting until i pressed <code>enter</code>) why is <code>Cmd5</code> waiting for my input. It should have also find <code>\n</code> in the beginning of input stream and assume that i didn't enter anything and take empty integer as input (similar to how <code>Cmd8</code> is behaving). What is happening here?</p>