// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class ToInt {
    public static int toInt(String s) {
        int res = Integer.parseInt(s);
        return res;
    }
    public static int toIntX(String s) {
        int res = 0;
        for(int i = 0; i < s.length(); i++) {
            res = 10 * res + (s.charAt(i) - '0');
        }
        return res;
    }
    public static int toIntXX(String s) {
        int res = 0;
        for(int i = 0; i < s.length(); i++) {
            res = 10 * res + (s.charAt(i) - '0');
        }
        return res;
    }
    public static void test(String s) {
        System.out.printf("\"%s\" : %d\n", s, toInt(s));
        System.out.printf("\"%s\" : %d\n", s, toIntX(s));
        System.out.printf("\"%s\" : %d\n", s, toIntXX(s));
    }
    public static void main(String[] args) throws Exception {
        test("1");
        test("12");
        test("123");
    }
}
