Why won't this JAVA code work as expected? : <p>So, this seems fairly simple bit of code.But when I run this, it gives me strange output.
First, I store the number of elements of <code>queries[] Array</code> in <code>NumQ</code> variable.Then, I store the values of elements by looping from 0 to numQ-1.It works in any other case.</p>

<pre><code>int numQ=sc.nextInt();
  String queries[]=new String[numQ];
    for(int i=0;i&lt;numQ;i++){

        queries[i]=sc.nextLine();
    }
System.out.println(queries[0]);
System.out.println(queries[1]);
System.out.println(queries[2]);
</code></pre>

<p>In my case, inputs are-(note that it even doesn't ask for the value at index 2.numQ is 3)</p>

<p><a href="https://i.stack.imgur.com/fTWX6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fTWX6.png" alt="enter image description here"></a></p>

<p>And here is the output.</p>

<p><a href="https://i.stack.imgur.com/tRyIl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tRyIl.png" alt="Output of the code"></a></p>

<p>See, at <code>queries[0]</code>, it stores blank value(blue selection is blank).At <code>queries[ 1 ]</code>, it stores the first input(which was to be stored at index 0.And it stores the index 1 value at index 2 and so on.)</p>

<p>So what's the problem with my code.
Thanks in advance:-)</p>
