AP CA A Unit 4 Review

AP CA A Unit 4 Review

11th - 12th Grade

20 Qs

quiz-placeholder

Similar activities

29W Quiz 1 - PLTW

29W Quiz 1 - PLTW

8th - 12th Grade

15 Qs

Fundamentals of Programming (GCSE Computer Science AQA)

Fundamentals of Programming (GCSE Computer Science AQA)

9th - 11th Grade

22 Qs

CSS Basics

CSS Basics

6th - 12th Grade

21 Qs

Loops Quiz

Loops Quiz

11th Grade

22 Qs

Arduino Loop

Arduino Loop

2nd Grade - University

20 Qs

Loops

Loops

5th - 12th Grade

16 Qs

For Loop python

For Loop python

5th - 12th Grade

19 Qs

Python-Basic

Python-Basic

3rd Grade - University

15 Qs

AP CA A Unit 4 Review

AP CA A Unit 4 Review

Assessment

Quiz

Computers

11th - 12th Grade

Hard

Created by

Sammi McConnell

Used 60+ times

FREE Resource

20 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

What is output to the screen by the following code?

2 1 0 3 2 1 0 3 2 1

1 0 3 2 1 0 3 2 1 0

1 0 3 2 1 0 3 2 1

1 2 3 0 1 2 3 0 1 2

Answer explanation

This has the correct number of iterations and the correct pattern

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

Assuming that s is a correctly initialized String (that does not end in a space) which of the following best describes what the algorithm below does?

Prints the number of times a space appears in str.

Prints the character after each space in str.

Prints the character before each space in str

Prints each character in str followed by a space.

Answer explanation

The indexOf function returns the index of the first appearance of a character. For each iteration the character in str after this is printed, then str is replaced by everything after that space. This continues until indexOf (“ “) returns -1 when there are no spaces left

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

What is output by the following code?

saopmoee

saompoeel

aspoomee

Nothing is printed because there is an out of bounds error

Answer explanation

The code iterates forwards through str1 (“awesome”) starting at s and backwards through str2 (“leopard”) starting at a. It starts printing a character from str1 then str2 going back and forth until st1 runs out of letters in which case the loop ends.

4.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Which of the following statements will return a random odd number between 5 and 15 inclusive?

2 * (int) (6 * Math.random()) + 5

2 * (int) (6 * Math.random() + 5)

(int) (2 * 5 * Math.random() + 5)

2 * (int) (5 * Math.random()) + 5

Answer explanation

This is correct. The Math.random() method returns a random double between 0, inclusive and 1 exclusive. Therefore 6 * Math.random() will return a random double which is greater than or equal to 0 and smaller than 6. When this is cast to an int, the nearest integer value below will be returned. Therefore (int) (6 * Math.random()) will be an int between 0 and 5 inclusive. Multiplying this by 2 ensures every other number is printed: 2 * (int) (6 * Math.random()) returns a random number between 0, 2, 4, 6, 8 or 10 inclusive, and then shifting by 5 creates the values 5, 7, 9, 11, 13, 15

5.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

Set the following for loop header so that it prints the numbers, 10 5 0 -5 -10.

10, > -10, -= 5

10, >= -10, -= 5

-10, <= 10, ++

10, > 10, -= 5

Answer explanation

i starts as 10, decreases by 5 each time, and no longer runs once the value of i is less than -10, so 10 5 0 -5 and -10 are printed

6.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

Media Image

What does short circuit evaluation mean in the following code?

if a >= b is false it evaluates c != d

if a >= b is false it doesn't evaluate c != d

if a >= b is true it evaluates c != d

c != d is evaluated first, and if true it evaluates a >= b

Answer explanation

This is correct and is how short circuit evaluations works in an && expression (Short-circuit evaluation means that when evaluating boolean expressions (logical AND and OR ) you can stop as soon as you find the first condition which satisfies or negates the expression.)


-Explanation of why option if a >= b is true it evaluates c != d is wrong: Even though this is true, it does not represent short circuit evaluation and how it works.

7.

MULTIPLE SELECT QUESTION

1 min • 1 pt

Media Image

For which of the following replacements for /* missing condition */ will the segment result in an infinite loop? (May choose more than one)

I. a > 0

II. a == 12

III. a % 3 != 5

Answer explanation

Both of these conditions will result in an infinite loop

I - Since a starts at 5, which is great than 0, and because a is increased each time through the loop, it will always be greater than 0, this will result in an infinite loop, but it is not the only condition to cause an infinite loop


II - This will actually result in a loop that never runs


III - Since a value of a % 3 can only equal 0, 1 or 2, regardless of what the value of a is increased to, it will never equal 5, so the loop will always run, but is is not the only condition to cause an infinite loop

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?