Omkant Parashetty wrote:Note: If I uncomment line num 9 it works fine !! can you please give some inputs on this.
I'm probably the wrong person to answer this, since I dislike
Scanner intensely; but it has something to do with "consuming the newline".
I presume that after you enter each string, you press the ENTER key. Well (I think), the first
nextLine() consumes the newline for the
first string you entered, and the second one reads the second string AND the newline, leaving the
Scanner ready to read the third string.
Personally, I find it all very counter-intuitive - and actually contrary to the docs for
next() (but maybe I'm misinterpreting them) - which is why I generally just use
nextLine() to get stuff. But, as I say, I'm not a big fan of
Scanner.
I'm sure Campbell will be along to correct me if I'm wrong. He usually is...
Winston