Dealing with strings (esp. leading spaces and/or end of line)
Leading spaces
The easiest way to remove leading spaces (such as a tab or blank) is to use the trim() function. So as an example:
line = datafile.nextLine();
line = line.trim();
Dealing with the end of line
After reading a number, if the next input is to be a string on a new line, be sure to read the rest of the current line. Example:
number = keyboard.nextInt();
keyboard.nextLine();