Ask your own question, for FREE!
Mathematics 16 Online
OpenStudy (anonymous):

I called: example3(2); public static void example3(int n){ if(n>0){ example3(n-1); } System.out.print(n + " "); } I know the output is 0 1 2. I don't know why the 2 is outputted though. First thing that happens is example3(2-1), which is 1. Then example3(1-1), which is 0. But where does the 2 come from?

OpenStudy (anonymous):

You have the following function defined: public static void example3(int n) { if (n > 0) example3(n - 1); System.out.print(n + " "); } If you call example3(2), this is what happens: 1. example3(1) is called. 2. example3(0) is called. 3. 0 is displayed and we return to step 2. 4. 1 is displayed and we return to step 1. 5. 2 is displayed and the program terminates.

OpenStudy (anonymous):

Remember that this is not a tail-recursive function, and as a result, things still happen even after the base case is reached.

OpenStudy (anonymous):

Thank you!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Latest Questions
Breathless: Spooky witch but cute
5 hours ago 3 Replies 0 Medals
Arriyanalol: help
5 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
7 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
7 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!