How recursion works is you break down to the base case and build up backwards. In your case. Your base case was x>=5, the point at which it would stop expanding the recursive tree, you can think of the base case as the end of the tree, or leaf. After that it goes back up completing things that were to be done after run was called. SO in your case, each time after calling one, it printed out x.
When x=1, it calls run(2), after run(2) is resolved, it would go to the next line. After run(2), the print out is 5 4 3 2 after that it would print out x coming back to the original call of run(1), which would be 1. This is really great for traversing trees etc and a lot of other problems.
To picture it, when you call run(1)
run(1)
1<5
run(2)
2<5
run(3)
3<5
run(4)
4<5
run(5)
print(5)
print(4)
print(3)
print(2)
print(1)
As you can see it goes to the base case, and back up.
To get familiar with recursion more, you can do problems like, finding the largest int in an array with the method head being public int findLargest(int [] array, int someNumber) where you would use someNumber to whatever you think you need. Or reversing a string using recursion and one parameter.
1 2 3 4 5, each on a new line. Recursion as a concept can be seen like having a camera with a detached (live) screen having its lens pointing at its screen, which in turn shows the screen and its image being repeated within the screen of the original image endlessly, except each time smaller. Just like in your case. Your methodrun()is callingrun()again and again, each time giving it a larger number until the condition is met (in this case, until the number is 5).1 2 3 4 5. Printing is done after the recursion stage, not before. It will be the exact opposite of what you said, i.e.5 4 3 2 1. Please check before posting.out.println(x);as being the first thing that happens in the method (before the conditional). Cheers!