java - Can't understand the result of recursion -
java - Can't understand the result of recursion -
i have code:
public static void main(string[] args) { system.out.println(f(4)); } public static int f(int n){ if(n == 1) homecoming 1; homecoming n / f(n - 1); }
why code homecoming 4 ?
f(1)
explicitly homecoming 1
f(2)
give 2/f(1)==2/1==2
f(3)
give 3/f(2)==3/2==1
(int division)
f(4)
give 4/f(3)==4/1==4
java recursion
Comments
Post a Comment