Search Header Logo

AP CSA Recursion (10.1)

Authored by Herman Galioulline

Computers

10th Grade

Used 6+ times

AP CSA Recursion (10.1)
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

6 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Which of the following best describes the output produced by the method call mystery(val)?

All integers from 1 to val, separated by spaces

All integers from val to 1, separated by spaces

The digits of val in their original order, separated by spaces

The digits of val in reverse order, separated by spaces

The last digit of val, then a space, then the first digit of val

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following method, which is intended to return the sum of all the even digits in its parameter num. For example, sumEvens(15555234) should return 6, the sum of 2 and 4.

Which of the following can be used as a replacement for /* missing statement */ so that the sumEvens method works as intended?

return sumEvens(num % 10);

return sumEvens(num / 10);

return num % 10 + sumEvens(num % 10);

return num % 10 + sumEvens(num / 10);

return num / 10 + sumEvens(num % 10);

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Which of the following best describes the result of the call doSomething(myString)?

The method call returns a String containing the contents of myString unchanged.

The method call returns a String containing the contents of myString with the order of the characters reversed from their order in myString.

The method call returns a String containing all but the first character of myString.

The method call returns a String containing only the first and second characters of myString.

The method call returns a String containing only the first and last characters of myString.

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Which of the following best describes the value returned by the method call calc(num)?

The int value 9

The leftmost digit of num

The rightmost digit of num

The number of digits in num

The result of the integer division of num by 10

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following recursive method, which is intended to return a String with any consecutive duplicate characters removed. For example, removeDupChars("aabcccd") returns "abcd".

Which of the following can replace /* missing code */ so that removeDupChars works as intended?

return removeDupChars(str.substring(2));

return removeDupChars(str.substring(1)) + str.substring(0, 1);

return removeDupChars(str.substring(2)) + str.substring(1, 2);

return str.substring(0, 1) + removeDupChars(str.substring(1));

return str.substring(1, 2) + removeDupChars(str.substring(2));

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following recursive method, which is intended to display the binary equivalent of a decimal number. For example, toBinary(100) should display 1100100.

Which of the following can replace /* missing code */ so that toBinary works as intended?

System.out.print(num % 2);

toBinary(num / 2);

System.out.print(num / 2);

toBinary(num % 2);

toBinary(num % 2);

System.out.print(num / 2);

toBinary(num / 2);

System.out.print(num % 2);

toBinary(num / 2);

System.out.print(num / 2);

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?