Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ch03/ScannerBug.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ public static void main(String[] args) {
name = in.nextLine();
System.out.print("What is your age? ");
age = in.nextInt();
in.nextLine(); // Consume the newline character after reading the age.
System.out.printf("Hello %s, age %d\n", name, age);

in.reset();
System.out.println();

System.out.print("What is your age? ");
age = in.nextInt();
in.nextLine(); // Consume the newline character after reading the age.
System.out.print("What is your name? ");
name = in.nextLine();
System.out.printf("Hello %s, age %d\n", name, age);
Expand Down