Ok. This is going to be a Question and Answer type. I found the answer for my question just now.
I have placed the
nextLine method just after the
nextInt/nextDouble method.
I forgot the fact that
nextInt method wouldn't read the "/n"
newline character that is given through stdin by user.
So before placing the
nextLine method, a blank
scan.nextLinemethod would read through the "/n"
newline character.
Corrected code looks like this:
scan.nextLine();
String s;
s = scan.nextLine();