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 queries[] Array
in NumQ
variable.Then, I store the values of elements by looping from 0 to numQ-1.It works in any other case.
int numQ=sc.nextInt();
String queries[]=new String[numQ];
for(int i=0;i<numQ;i++){
queries[i]=sc.nextLine();
}
System.out.println(queries[0]);
System.out.println(queries[1]);
System.out.println(queries[2]);
In my case, inputs are-(note that it even doesn't ask for the value at index 2.numQ is 3)
And here is the output.
See, at queries[0]
, it stores blank value(blue selection is blank).At queries[ 1 ]
, 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.)
So what's the problem with my code. Thanks in advance:-)