Program Implementation

Help Questions

AP Computer Science A › Program Implementation

Questions 1 - 10
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

Explanation

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.

2

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

Explanation

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.

3

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

Explanation

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.

4

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

Explanation

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.

5

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

Explanation

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.

6

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

Explanation

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.

7

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

Explanation

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.

8

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

Explanation

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.

9

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

Explanation

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.

10

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

Explanation

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.

Page 1 of 100
Return to subject