// 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 IsInt {
    private static boolean isInt(String s) {
        boolean res;
        if((s == null) || (s.length() == 0)) {
            res = false;
        } else {
            res = true;
            for(int i = 0; i < s.length(); i++) {
                if((s.charAt(i) < '0') || ('9' < s.charAt(i))) {
                    if((i != 0) || (s.charAt(i) != '-')) {
                        res = false;
                    }
                }
            }
        }
        return res;
    }
    private static boolean isIntX(String s) {
        boolean res;
        if((s == null) || (s.length() == 0)) {
            res = false;
        } else {
            res = true;
            for(int i = 0; i < s.length(); i++) {
                if((s.charAt(i) < 48) || (57 < s.charAt(i))) {
                    if((i != 0) || (s.charAt(i) != 45)) {
                        res = false;
                    }
                }
            }
        }
        return res;
    }
    private static void test(String s) {
        System.out.printf("\"%s\" : %b\n", s, isInt(s));
        System.out.printf("\"%s\" : %b\n", s, isIntX(s));
    }
    public static void main(String[] args) throws Exception {
        test("123");
        test("-123");
        test("ABC");
        test("123X");
        test("");
    }
}
