/** Demo 3 October */
public class Demo {
    
    /** =  a copy of s in which s[0..1] are swapped,
           s[2..3] are swapped, s[3..4] are swapped, etc.
           swapAdjacent("abcdefg") is "badcfeg" */
    public static String swapAdjacent(String s) {
        if (s.length() <= 1) {
          return s;   
        }
        
        // s has at least 2 characters
        // return s[1]+ s[0] + (swap of adjacent pairs of s[2..])
        return "" + s.charAt(1) + s.charAt(0) +
            swapAdjacent(s.substring(2));
    }
    
    /** =  b**c. Precondition: c ³ 0*/
    public static int exp(int b, int c) {
        if (c == 0) {
           return 1;    
        }
        
        // c >= 1
        if (c % 2 == 0) {
          return exp(b*b, c/2);   
        }
        
        // c >= 1 and its odd
        return b*exp(b,c-1);  
    }
    
    /** = F(n). Precondition: n >= 0 */
    public static int Fib(int n) {
        if (n <= 1) {
           return n;   
        }
        
        // n >= 2
        return Fib(n-1) + Fib(n-2);
    }
}