//TestScannerWithString.java

import java.util.Scanner;

public class TestScannerWithString
{
    public static void main(String args[])
    {
        //Initializing a Scanner with a String
        String s = "The quick brown fox jumped over the lazy dogs.";
        Scanner stringStream = new Scanner(s);
        while (stringStream.hasNext())
        {
            System.out.println(stringStream.next());
        }

        //Initializing a Scanner with a String containing integers
        String stringOfInts = "1 2 3 4 5";
        Scanner intReader = new Scanner(stringOfInts);
        int sum = 0;
        while (intReader.hasNext())
        {
            sum += Integer.parseInt(intReader.next());
        }
        System.out.println(sum);

        //Using a differenct delimiter
        String anotherStringOfInts = "1!2!3!4!6";
        Scanner anotherIntReader = new Scanner(anotherStringOfInts);
        anotherIntReader.useDelimiter("!");
        sum = 0;
        while (anotherIntReader.hasNext())
        {
            sum += Integer.parseInt(anotherIntReader.next());
        }
        System.out.println(sum);
    }
}

