0

Why this problem print 2?

public class Program { public static void main(String[] args){ System.out.println(tri(3)); } static int tri(int n){ return n==0 ? 0 : n ==1 ? 1 : tri(n-1) + tri(n-2); } }

16th Sep 2020, 7:43 PM
Juan Debenedetti
Juan Debenedetti - avatar
1 Resposta
+ 2
n = 3 return tri(2)+tri(1) tri(2) return tri(1)+ tri(0) tri(1) return 1 tri(0) return 0 So 1+1+0
16th Sep 2020, 7:48 PM
[][]