logo CodeStepByStep logo

recursionMystery1X

Language/Type: Java recursion

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

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

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.