logo CodeStepByStep logo

recursionMysteryPrintDigits

Language/Type: Java recursion

For each call to the following recursive method, write the output that would be produced, as it would appear on the console.

public static void recursionMysteryPrintDigits(int x) {
    if (x < 10) {
        System.out.print(x);
    } else {
        int y = x % 10;
        System.out.print(y);
        recursionMysteryPrintDigits(x / 10);
        System.out.print(y);
    }
}
recursionMysteryPrintDigits(7);
recursionMysteryPrintDigits(38);
recursionMysteryPrintDigits(194);
recursionMysteryPrintDigits(782);
recursionMysteryPrintDigits(3842);

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.