Suppose you have code that is not shown that the scanner uses to try to get lastName. In this attempt, you are not processing the end-of-line marker, and therefore it has remained dangling, only to absorb the call nextLine()where you are trying to get lastName.
For example, if you have this:
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboard.nextInt();
System.out.print("Last name: ");
lastName = keyboard.nextLine();
You will have problems.
, , EOL, , keyboard.nextLine().
,
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = keyboard.nextInt();
keyboard.nextLine();
System.out.print("Last name: ");
lastName = keyboard.nextLine();