logo CodeStepByStep logo

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

recursionMystery8

Language/Type: Java recursion

For each call to the following recursive method, write the output that is produced as it would appear on the console. Hint: To avoid re-tracing out long chains of calls, it may help you to look at your own notes on call results that you have already previously computed, and re-use those results as applicable.

public static void recursionMystery8(int n) {
    if (n <= 1) {
        System.out.print(n);
    } else {
        System.out.print(n + " = (");
        recursionMystery8(n / 2 + n % 2);
        System.out.print(", ");
        recursionMystery8(n / 2);
        System.out.print(")");
    }
}
recursionMystery8(3);
recursionMystery8(4);
recursionMystery8(6);
recursionMystery8(7);

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.