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

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -