logo Practice-It logo

Recursive Tracing

Language/Type: Java mod recursion recursive tracing
Author: Marty Stepp (on 2014/02/13)

For each call to the following recursive method, indicate what output is produced:

    public void mystery(int n) {
        if (n < 0) {
            System.out.print("-");
            mystery(-n);
        } else if (n < 10) {
            System.out.println(n);
        } else {
            int two = n % 100;
            System.out.print(two / 10);
            System.out.print(two % 10);
            mystery(n / 100);
        }
    }
mystery(7);
mystery(825);
mystery(38947);
mystery(612305);
mystery(-12345678);

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.