AP计算机教程10-4:简单多选题
0:00
Which line has the recursive call?
public static int factorial(int n)
{
if (n == 0)
return 1;
else return n * factorial(n-1);
}
第5行method调用了自己。
4
Which line has the recursive call?
public String starString(int n)
{
if (n == 0) {
return "*";
} else {
return starString(n - 1) + starString(n - 1);
}
}
第6行method调用了自己。
5
How many recursive calls does the following method contain?
public static int fibonacci(int n)
{
if (n == 0)
return 0;
else if (n == 1)
return 1;
else return fibonacci(n-1) + fibonacci(n-2);
}
第7行有两次递归调用。
3
How many recursive calls does the following method contain?
public static int multiplyEvens(int n)
{
if (n == 1) {
return 2;
} else {
return 2 * n * multiplyEvens(n - 1);
}
}
第6行有一次递归调用。
2
0 条评论