Java - Understanding Recursion
java, recursion
Solution
It is pretty simple, these are the calls
main
xMethod(5)
xMethod(4)
xMethod(3)
xMethod(2)
xMethod(1)
xMethod(0)
print 1
print 2
print 3
print 4
print 5
So you see the prints are 1,2,3,4,5
Problem
Can someone please explain to me why this prints out 1 2 3 4 5? I figured it would print out 4 3 2 1 0 but my book and eclipse both say I'm wrong. ``` public class whatever { /** * @param args */ public static void main(String[] args) { xMethod(5); } public static void xMethod(int n){ if (n>0){ xMethod(n-1); System.out.print(n + " "); } } } ```