package com.mindprod.example;

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

/**
 * Demonstrate the use of Scanner
 * <p/>
 * composed with IntelliJ IDEA
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0,  2007-09-16
 */
public class TestScanner
    {
    // --------------------------- main() method ---------------------------

    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"/* encoding */ );

        // 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();
                System.out.println( i );
                }
            }
        catch ( InputMismatchException e )
            {
            System.err
                    .println( "problem reading scanner stream: "
                              + e.getMessage() );
            }
        sc.close();
        }
    }