AP Computer Science A › Program Implementation
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.
Which of the following is a recursive factorial function?
Recall that an example of a factorial is:
public long factorial(long a) {
if(a <= 1) {
return 1;
}
return a * factorial(a-1);
}
public long factorial(long a) {
a * a-1 * a-2 * a-3 * a-4;
}
public long factorial(long a) {
long ret = 1;
for(int i = 2; i < a; i++) {
ret *= i;
}
return ret;
}
public long factorial(long a) {
return a * factorial(a-1) * factorial(a-2);
}
None of the others
Recall that a recursive function calls itself. Therefore, you can eliminate several of the answers just by the fact that they are not recursive in nature. (Indeed the one with a loop is a correct computation.) Now, you can think of a factorial like this:
And then...
And so forth.
Thus, you have a stopping case at 1, which is equal to 1. For any other value, you will return a recursive value, namely the parameter a and then the factorial method called with a-1.