• Post Reply Bookmark Topic Watch Topic
  • New Topic

Recursive method  RSS feed

 
natt walters
Greenhorn
Posts: 17
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
natt walters
Greenhorn
Posts: 17
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!