logo CodeStepByStep logo

recursionMystery10

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.

public static void recursionMystery10(int x) {
    System.out.print(x + " ");
    if (x <= 1) {
        System.out.print("END ");
    } else if (x % 2 == 0) {
        recursionMystery10(x / 2);
        System.out.print("+ ");
    } else {
        System.out.print("[ ");
        recursionMystery10(3 * x + 1);
        System.out.print("] ");
    }
}
recursionMystery10(1);
recursionMystery10(4);
recursionMystery10(3);

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.