logo Practice-It logo

Recursive Tracing

Language/Type: Java recursion recursive tracing
Author: Marty Stepp and Helene Martin (on 2014/02/13)

For each of the calls to the following recursive method below, indicate what output is produced:

public static void mystery(int x, int y) {
    if (y <= 0) {
        System.out.print("0 ");
    } else if (x > y) {
        System.out.print(x + " ");
        mystery(x - y, y);
    } else {
        mystery(x, y - x);
        System.out.print(y + " ");
    }
}
mystery(6, 3);
mystery(2, 3)
mystery(5, 8);
mystery(21, 12);
mystery(3, 10);

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.