It doesn't run "fine" that's for sure. If you're taking input from the command line, then it seems to run fine, but if stdio is redirected from a file you'll have an issue.
nextInt doesn't move to the next line, it leaves the end of line characters in the stream. Therefore nextLine reads an empty string.