logo Practice-It logo


Language/Type: Java recursion recursive tracing
Author: Marty Stepp (on 2012/02/15)

For each call to the following method, 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.