logo Practice-It logo

recursiveTracing

Language/Type: Java recursion recursive tracing
Author: Eric Spishak

Recursive Tracing. For each call to the following method, indicate what value is returned:

public static int mystery(int n) {
    if (n < 0) {
        return -mystery(-n);
    } else if (n == 0) {
        return 0;
    } else {
        return mystery(n / 10) * 10 + 9 - (n % 10);
    }
}
mystery(0)
mystery(5)
mystery(13)
mystery(297)
mystery(-3456)

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.