+ 1
Can anyone explain it?? Why output is 5?
// Created by Rashed //how this is output 5 public class Program { public static int f(int x){ if (x==0) return 2; else return 1 + f(x-1); } public static void main(String[] args) { System.out.println(f(3)); } }
2 Antworten
+ 2
Print the return for each instance and it will be clear.
f(0) = 2; f(1) = f(0)+1; f(2) = f(1)+1; f(3)=f(2)+1
0
Thanks bro..JME