can any one help me figure out how this recursion done?
public class RecursiveMethodSum { public static int sum(int n) { if (n == 1) { return 1; } else { return n + sum(n - 1); } } public static void main(String[] args) { int x = sum(4); System.out.println(x); } }
output
10
one question is... during the process of the recursion... (4 + (4 -1)) its == 7? ryt?
but where does the number seven goes? i can only see the the process is just adding
the value that has been passed to the parameter... where are the sum(s)?