The problem is probably due to the way the Scanner class's nextLine method and next... methods work.
It is explained here: ...