67.6k views
0 votes
Consider the recursive method myprint in this code snippet: public void myprint(int n) { if (n < 10) { system.out.print(n); } else { int m = n % 10; system.out.print(m); myprint(n / 10); } } what is printed for the call myprint(821)?

1 Answer

6 votes
What the method does, is it takes the rightmost decade and prints it, then divides by 10 and repeats. Effectively this means the number is printed backwards, so the output is 128.
User Przemyslaw
by
8.0k points