AP CA A Unit 4 Review
Flashcard
•
Computers
•
11th - 12th Grade
•
Hard
Wayground 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
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?
Similar Resources on Wayground
17 questions
Higher Chemistry - Unit 3 - Equilibrium
Flashcard
•
11th Grade
12 questions
Product Design and Process Selection
Flashcard
•
University
6 questions
Unit 3.8 Market Structure
Flashcard
•
11th Grade
13 questions
Industrial Revolution
Flashcard
•
10th Grade
10 questions
Strategies to Avoid Communication Breakdown
Flashcard
•
11th - 12th Grade
10 questions
Marketing Mix - Place and Distribution
Flashcard
•
10th Grade - University
10 questions
Alone Vocab part 5
Flashcard
•
9th - 12th Grade
8 questions
1.1 GCSE Computing: CPU Components
Flashcard
•
10th Grade
Popular Resources on Wayground
10 questions
Ice Breaker Trivia: Food from Around the World
Quiz
•
3rd - 12th Grade
20 questions
MINERS Core Values Quiz
Quiz
•
8th Grade
10 questions
Boomer ⚡ Zoomer - Holiday Movies
Quiz
•
KG - University
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
Adding Integers
Quiz
•
6th Grade
20 questions
Multiplying and Dividing Integers
Quiz
•
7th Grade
10 questions
How to Email your Teacher
Quiz
•
Professional Development
15 questions
Order of Operations
Quiz
•
5th Grade