// 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 IntervalFind {
    private final static String VALID = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static String next(String s) {
        StringBuffer sb = new StringBuffer(s);
        int ix = s.length() - 1;
        boolean more = true;
        while (more) {
            int val = VALID.indexOf(s.charAt(ix)) + 1;
            if(val < VALID.length()) {
                sb.setCharAt(ix, VALID.charAt(val));
                more = false;
            } else {
                sb.setCharAt(ix, VALID.charAt(0));
                ix--;
            }
        }
        return sb.toString();
    }
    public static void loop(String lastprev, String firstnext) {
        String s = next(lastprev);
        while (!s.equals(firstnext)) {
            System.out.println(s);
            s = next(s);
        }
    }
    public static void main(String[] args) {
        loop("AAA3", "AABB");
    }
}
