AP计算机教程10-5:中等多选题
0:00
Given the method defined below what does the following print: mystery(1234)
?
public static void mystery (int x) { System.out.print(x % 10); if ((x / 10) != 0) { mystery(x / 10); } System.out.print(x % 10); }
注意在递归前后各有一个
print
,故是先倒序再顺序。4
Given the following method declaration, what value is returned as the result of the call mystery(5)
?
public static int mystery(int n) { if (n == 0) return 1; else return 3 * mystery (n - 1); }
结果是
3
的五次方。1
Given the following method declaration, what value is returned as the result of the call product(5)
?
public static int product(int n) { if (n <= 1) return 1; else return n * product(n - 2); }
结果是\(5\times3\times1=15\)。
5
Given the following method declaration, what value is returned as the result of the call f(5)
?
public static int f(int n) { if (n == 0) return 0; else if (n == 1) return 1; else return f(n-1) + f(n-2); }
f(2)
为1
,f(3)
为2
,f(4)
为3
,f(5)
为5
。4
0 条评论