int foo(int x, int y){ if (x <= 0 || y <= 0) return 1; return 3 * foo( x-6, y/2 ); }
3
9
27
81
解析:foo(20, 13) = 3 * foo(14, 6) = 3 * 3 * foo(8, 3) = 3 * 3 * 3 * foo(2, 1) = 3 * 3 * 3 * 3 * foo(-4, 0) =3 * 3 * 3 * 3 * 1 = 81
答案:D
class Main { static int foo(int x, int y){ if (x <= 0 || y <= 0) return 1; return 3 * foo( x-6, y/2 ); } public static void main(String[] args) { System.out.println(foo(20,30)); } }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题
解析:foo(20, 13) = 3 * foo(14, 6) = 3 * 3 * foo(8, 3) = 3 * 3 * 3 * foo(2, 1) = 3 * 3 * 3 * 3 * foo(-4, 0) =3 * 3 * 3 * 3 * 1 = 81
答案:D