logo CodeStepByStep logo

recursionMystery3

Language/Type: Java recursion

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

public static int recursionMystery3(int n) {
    if (n < 0) {
        return -recursionMystery3(-n);
    } else if (n < 10) {
        return (n + 1) % 10;
    } else {
        return 100 * recursionMystery3(n / 10) + (n + 1) % 10;
    }
}
recursionMystery3(7)
recursionMystery3(42)
recursionMystery3(385)
recursionMystery3(-790)
recursionMystery3(89294)

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.