/** demo for 17 feb 2005
 */
public class Demo {
    
    /** = max of x and y */
    public static int max(int x, int y) {
        // Swap x,y if necessary to put max in x
        if (x < y) {
            int temp;
            temp= x;
            x= y;
            y= temp;
        }
        
        
        return x;
    }
    
    
    /** s contains a name in the form "David Gries".
     * There may be more than one blank between the names.
     * Return the same name in this form: "Gries, David"
     * with exactly one blank between the comma and the first name
     * */
    public static String switchFormat(String s) {
        // Store in k the index of first blank
        int k= s.indexOf(' ');
        
        // Save s[0..k-1] in firstN and remove it from s
        String firstN= s.substring(0,k);
        s= s.substring(k);
        
        // Remove blanks from beginning of s
        s= s.trim();
        
        return s + ", " + firstN;
    }
    
    
    
    
    
    
    
    /** s consists of a sequence of words separated
     *  by one or more blanks. s may start with a blank.
     *  s has at least one word. Return a TwoString that
     *  contains (first word of s, rest of s).
     *  e.g. for s = " bbb ccccc   dd", return the value of
     *     new TwoString("bbb", "ccccc   dd").
     */
    public static TwoString strip(String s) {
        // Remove the initial and final blanks from s
        s= s.trim();
        
        // Store in k index of char following the first word
        int k= s.indexOf(' ');
        if (k == -1)
            k= s.length();
        
        // Store s[0..k-1] in f and remove it from s
        String f= s.substring(0,k);
        s= s.substring(k);
        
        return new TwoString(f, s);
        
    }
    
    
    
}