AP CA A Unit 4 Review

Flashcard
•
Computers
•
11th - 12th Grade
•
Hard
Quizizz Content
FREE Resource
Student preview

16 questions
Show all answers
1.
FLASHCARD QUESTION
Front
What is output to the screen by the following code? Options: 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
Back
1 0 3 2 1 0 3 2 1 0
Answer explanation
This has the correct number of iterations and the correct pattern
2.
FLASHCARD QUESTION
Front
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.
Back
Prints the character after each space in str.
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.
FLASHCARD QUESTION
Front
What is output by the following code? Options: saopmoee, saompoeel, aspoomee, Nothing is printed because there is an out of bounds error
Back
saopmoee
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.
FLASHCARD QUESTION
Front
Which of the following statements will return a random odd number between 5 and 15 inclusive? Options: 2 * (int) (6 * Math.random()) + 5, 2 * (int) (6 * Math.random() + 5), (int) (2 * 5 * Math.random() + 5), 2 * (int) (5 * Math.random()) + 5
Back
2 * (int) (6 * 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.
FLASHCARD QUESTION
Front
Set the following for loop header so that it prints the numbers, 10 5 0 -5 -10. Options: 10, >= -10, -= 5, 10, > -10, -= 5, -10, <= 10, ++, 10, > 10, -= 5
Back
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.
FLASHCARD QUESTION
Front
What does short circuit evaluation mean in the following code? Options: 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
Back
if a >= b is false it doesn't evaluate c != d
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.
FLASHCARD QUESTION
Front
Assume that x and y are boolean variables and have been properly initialized. What is the result of the expression?
Back
Always true
Answer explanation
No matter the boolean values, the whole expression evaluates to true
Create a free account and access millions of resources
Similar Resources on Wayground
13 questions
Python variables, expressions, and data types

Flashcard
•
9th - 12th Grade
11 questions
Java ArrayLists

Flashcard
•
10th Grade
15 questions
Unit 5 Lessons 0 & 1

Flashcard
•
10th Grade
15 questions
Intro to Java Loops

Flashcard
•
9th - 12th Grade
14 questions
Halloween Java

Flashcard
•
12th Grade
18 questions
AP CSA Unit 1 Review

Flashcard
•
10th - 12th Grade
15 questions
AP CSP Unit 4

Flashcard
•
10th - 12th Grade
12 questions
JavaScript Programming Concepts

Flashcard
•
9th - 12th Grade
Popular Resources on Wayground
15 questions
Hersheys' Travels Quiz (AM)

Quiz
•
6th - 8th Grade
20 questions
PBIS-HGMS

Quiz
•
6th - 8th Grade
30 questions
Lufkin Road Middle School Student Handbook & Policies Assessment

Quiz
•
7th Grade
20 questions
Multiplication Facts

Quiz
•
3rd Grade
17 questions
MIXED Factoring Review

Quiz
•
KG - University
10 questions
Laws of Exponents

Quiz
•
9th Grade
10 questions
Characterization

Quiz
•
3rd - 7th Grade
10 questions
Multiply Fractions

Quiz
•
6th Grade