logo CodeStepByStep logo

recursionMystery4

Language/Type: Java recursion

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

public static void recursionMystery4(int n) {
    if (n <= 1) {
        System.out.print("*");
    } else if (n == 2) {
        recursionMystery4(n - 1);
        System.out.print("*");
    } else {
        System.out.print("(");
        recursionMystery4(n - 2);
        System.out.print(")");
    }
}
recursionMystery4(2);
recursionMystery4(3);
recursionMystery4(4);
recursionMystery4(6);
recursionMystery4(9);

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.