package parsestrings;
import java.util.Scanner;
public class ParseStrings {
 public static void main(String[] args) {
 Scanner scnr = new Scanner(System.in); // Input stream for standard input
 Scanner inSS = null; // Input string stream
 String lineString = ""; // Holds line of text
 String firstWord = ""; // First name
 String secondWord = ""; // Last name
 boolean inputDone = false; // Flag to indicate next iteration
 // Prompt user for input
 System.out.println("Enter input string: ");
 // Grab data as long as "Exit" is not entered
 while (!inputDone) {
 // Entire line into lineString
 lineString = scnr.nextLine()
 // Create new input string stream
 inSS = new Scanner(lineString);
 // Now process the line
 firstWord = inSS.next();
 // Output parsed values
 if (firstWord.equals("q")) {
 System.out.println("Exiting.");
 inputDone = true;
 if (firstWord.matches("[a-zA-Z]+,[a-zA-Z]+")) {
 System.out.print("Input not two comma separated words");
 }
 } else {
 secondWord = inSS.next();
 System.out.println("First word: " + firstWord);
 System.out.println("Second word: " + secondWord);
 System.out.println();
 }
 }
 return;
 }
}