import java.util.Scanner;

/**
 * Simple illustration of an issue when using Scanner.nextLine().
 * @author Hyrum D. Carroll
 * @version 0.1 (January 27, 2022)
 */

public class NextLineIssues_01{
    public static void main( String[] args ){
        int age = -1;
        String name;
        Scanner keyboard = new Scanner( System.in );

        //Input: 99\nDr. C\n
        System.out.print("Please enter your age: " );
        age = keyboard.nextInt();
        //Input: \nDr. C\n
        System.out.println( "You entered: " + age);
        String garbage = keyboard.nextLine(); // read in just the newline
        //Input: Dr. C\n
        System.err.println("DEBUGGING: garbage: '" + garbage + "' (should be an empty string)");

        System.out.print("Please enter your first and last name: " );
        name = keyboard.nextLine();
        //Input: 
        System.out.println( "You entered: \"" + name + "\"");
    }
}