/*
 * [TestScanner.java]
 *
 * Summary: Demonstrate the use of Scanner.
 *
 * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.8+
 *
 * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/
 *
 * Version History:
 *  1.0 2007-09-16
 */
package com.mindprod.example;

import java.util.InputMismatchException;
import java.util.Scanner;

import static java.lang.System.*;

/**
 * Demonstrate the use of Scanner.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2007-09-16
 * @since 2007-09-16
 */
public class TestScanner
    {
    public static void main( String[] args )
        {
        // First select a source of the data which
        // can be a file, InputStream, Channel or String...
        Scanner sc = new Scanner( System.in, "UTF-8" /* cannot be Charset */ );
        // By default the separator is whitespace.
        // Decide on a regex separator, in this case, vertical bar or newline
        sc.useDelimiter( "[\\|\\n]" );
        try
            {
            // loop reading until there are no more data
            while ( sc.hasNext() )
                {
                // read next field,  next for String, nextInt for int
                int i = sc.nextInt();
                out.println( i );
                }
            }
        catch ( InputMismatchException e )
            {
            err.println( "problem reading scanner stream: "
                         + e.getMessage() );
            }
        sc.close();
        }
    }