package scannerinput;

import java.util.Scanner;

public class InputMixed {
    public static void main(String[] args) {

        /*
         * A common problem with Scanner is that it's not very good at
         * dealing with mixed inputs.
         * Run this program:
         */

        Scanner input = new Scanner(System.in);
        System.out.println("Enter an integer: ");
        int num1 = input.nextInt();
        System.out.println("Your int: " + num1);

        System.out.println("---------");
        System.out.println("Enter a floating-point value:");
        double num2 = input.nextDouble();
        System.out.println("Your floating-point: " + num2);

        System.out.println("---------");
        System.out.println("Now enter a string.");
        String str = input.nextLine();
        System.out.println(str);

        // it didn't give us a chance to enter the String!!!! :( :(





































        
        
        /*
         * WHY?
         * The methods like next(), nextInt(), and nextDouble() will read
         * characters from the input buffer until they encounter
         * ANY kind of whitespace character.
         * They will read in those characters up to the whitespace, and
         * and will return those characters and leave ANYTHING ELSE
         * in the input buffer.
         * INCLUDING THE WHITESPACE
         * Normally that's not a problem: when next(), nextInt(),
         * nextDouble(), etc try to read from the input buffer and they
         * see some leftover whitespace, they just toss it away and eagerly
         * go for the actual characters.
         * So when the user types 10 [enter key], the nextInt() ignores any
         * leftover whitespace, grabs 10 and returns it, and leaves
         * the new-line characters in the buffer.
         * next(), nextDouble(), and all the others do the same thing.
         * EXCEPT nextLine().
         * First, nextLine() doesn't ignore tabs and spaces: it considers
         * those input characters just like letters and numbers.
         * Unlike other methods, nextLine() will read ALL characters
         * and only stop when it encounters a new-line character.
         * it doesn't ignore spaces and tabs that are left behind in
         * the input buffer. It only cares about the newline character
         * because that's how it knows when to stop reading data.
         *
         * So, when you call nextDouble() to get the double value,
         * and the user types 2.5 [enter], nextDouble() returns the 2.5
         * and leaves the newline in the buffer.
         * Now it's nextLine()'s turn: nextLine() goes to the buffer
         * to get characters and sees a newline sitting in there!
         * So it says, "Cool, that's my newline, I'm done!"
         * So the user doesn't get a chance to enter anything, because
         * nextLine() grabbed the leftover newline and left!
         * 
         * There are a couple of ways to get around this problem.
         * See ScannerFix1.java and ScannerFix2.java.
         */

        input.close();
    }
}
