#Recursion

5 messages · Page 1 of 1 (latest)

fair ruin
#

Struggling a little with recursion. I have this

public static void mystery(int n) {
      if (n > 0){
         mystery(n-1);
         System.out.print(n * 4);
         mystery(n-1);
      } 
   }

   public static void main(String[] args) {
      MysteryClass.mystery(3);
   } 
}```


And I am trying to understand exactly how it executes. But I am not getting it quite right. Would love for a good explanation of what it does exactly and what line executes when etc
slender wolfBOT
#

This post has been reserved for your question.

Hey @fair ruin! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

slender wolfBOT
fair ruin
#

I understand the basics of what the method should do, just not what order it is doing it recursively,