null means, nothing... 0
How about enter? that generates a newline right?values 0A in hex....
Try to print what
while(sc.nextLine() != null);
prints, since that comparison always true, then sc.nextLine() should have captured some text from console...
and i guess, that will prints "end of iteration"
try like,
while(sc.nextLine().equals("");
or another flag that could negate the comparison,
eg. if(sc.nextLine().equals("x") then terminate....