UNB/ CS/ David Bremner/ teaching/ java/ EvalNumber.java
public class EvalNumber{
    private static long evalNumber(String digits, int base){
        int len=digits.length();

        if (len==0)
            return 0;

        if (len==1)
            return evalDigit(digits);

        return base*evalNumber(digits.substring(0,len-1),base)
                               +evalDigit(digits.substring(len-1));
    }

    // FIXME: this only works for 0-9
    private static int evalDigit(String digit){
        return digit.charAt(0)-'0';
    }
        

    public static void main(String[] args){
        System.out.println(evalNumber("666",10));
        System.out.println(evalNumber("101",10));
        System.out.println(evalNumber("101",2));
    }

}