Αναδρομικές τεχνικές

Παράδειγμα

class Recurse {
        static void russian_doll(int size) {
                int i;

                System.out.print("[");
                for (i = 0; i < size; i++)
                        System.out.print("-");
                System.out.println("]");
                if (size > 1)
                        russian_doll(size - 1);
        }

        static int factorial(int n) {
                if (n == 0)
                        return (1);
                else
                        return (n * factorial(n - 1));
        }

        public static void main(String args[]) {
                System.out.println(factorial(5));
                russian_doll(10);
        }
}

Αποτελέσματα

120
[----------]
[---------]
[--------]
[-------]
[------]
[-----]
[----]
[---]
[--]
[-]