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 = "Empty";
        Scanner keyboard = new Scanner( System.in );

        System.out.print("Please enter your age: " );
        // Input: 37\nHanu Katt\n
        //        ^
        //        |
        // Read position marker

        age = keyboard.nextInt();
        // Input: 37\nHanu Katt\n
        //          ^
        //          |
        // Read position marker
        System.out.println( "You entered: " + age);

        System.out.print("Please enter your first and last name: " );
        // Advance the read position marker past the newline (setting it up to actually read the names)
        String emptyStr = keyboard.nextLine();
        System.err.println("DEBUGGING: emptyStr: " + emptyStr);
        // Input: 37\nHanu Katt\n
        //            ^
        //            |
        // Read position marker
        name = keyboard.nextLine();
        // Input: 37\nHanu Katt\n
        //                       ^
        //                       |
        //    Read position marker
        System.out.println( "You entered: \"" + name + "\"");
    }
}