Forums Register Login

Recursive method

+Pie Number of slices to send: Send


Can anybody please explain how would the statement

System.out.println("["+(i-1)+"] " +values[i-1];

be executed as the printarray is recursive and when the value of i reaches 0 the return statement executes terminating the method completely.
1
+Pie Number of slices to send: Send
When i reaches 0, the return statement only means "return from this particular method call". Control will then be passed to the calling method (where i = 1), and when that ends it will pass control to the method that called that, and so on till it reaches the original method.
+Pie Number of slices to send: Send
Thank you very much
+Pie Number of slices to send: Send
You're welcome.
Listen. That's my theme music. That's how I know I'm a super hero. That, and this tiny ad told me:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 537 times.
Similar Threads
Reading arrays
Var args once again......
August Newsletter Puzzle
Recursion
Conversion of 'Array object'!
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 18:35:33.