Source of DelimitersDemo.java


  1: 
  2: import java.util.Scanner;
  3: 
  4: public class DelimitersDemo
  5: {
  6:     public static void main(String[] args)
  7:     {
  8:         Scanner keyboard1 = new Scanner(System.in);
  9:         Scanner keyboard2 = new Scanner(System.in);
 10: 
 11:         keyboard2.useDelimiter("##");
 12:         //The delimiters for keyboard1 are the white space characters.
 13:         //The only delimiter for keyboard2 is ##.
 14: 
 15:         String s1;
 16:         String s2;
 17: 
 18:         System.out.println("Enter a line of text with two words:");
 19:         s1 = keyboard1.next( );
 20:         s2 = keyboard1.next( );
 21:         System.out.println("The two words are \"" + s1 +
 22:                                                    "\" and \"" + s2 + "\"");
 23: 
 24:         System.out.println("Enter a line of text with two words");
 25:         System.out.println("delimited by ##:");
 26:         s1 = keyboard2.next( );
 27:         s2 = keyboard2.next( );
 28:         System.out.println("The two words are \"" + s1 +
 29:                                                    "\" and \"" + s2 + "\"");
 30:     }
 31: }
 32: