logo CodeStepByStep logo

You are working on problem set: Unit 4 ( Pause)

recursionMystery2X

Language/Type: Java recursion

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

public static void recursionMystery2X(int n) {
    System.out.print("( ");
    helper(n);
    System.out.print(") ( ");
    helper(n);
    System.out.print(")");
}

public static void helper(int n) {
    if (n <= 1) {
        System.out.print(n + " = ");
    } else {
        System.out.print((n % 2) + " ");
        helper(n / 2);
        System.out.print(n + " ");
        n = n - 1;
    }
}
recursionMystery2X(8);
recursionMystery2X(25);
recursionMystery2X(46);

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? .

If something seems wrong with our site, please

Is there a problem? Contact us.