
APCSA Exam Review

Quiz
•
Computers
•
9th - 12th Grade
•
Hard
Daniel Geiter
Used 2+ times
FREE Resource
11 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
I Only
III Only
I and II Only
II and III only
I, II, and III
Answer explanation
In option I, the cast applies to the value 2, so floating-point
division is performed and the expression evaluates to 0.5 + 3, or 3.5. In option II, the cast applies to the result of the integer division 2 / 4, so the expression evaluates to 0.0 + 3, or 3.0. In option III, the cast applies to the sum of 3 and the result of the integer division 2 / 4, so the expression evaluates to (double) (0 + 3), or 3.0.
2.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the code segment to the left.
Which of the following statements assigns the same value to b2 as the code segment assigns to b1 for all values of num?
boolean b2 = (num > -100) && (num < 100);
boolean b2 = (num > -100) || (num < 100);
boolean b2 = (num < -100) || (num > 100);
boolean b2 = (num < -100) && (num > 0 || num < 100);
boolean b2 = (num < -100) || (num > 0 && num < 100);
Answer explanation
In the body of the first if clause in the code segment, b1
retains the value true if num is between 0 and 100, exclusive.
In the body of the else clause, b1 retains the value true if
num is less than -100. The statement assigns true to b2 if
num is less than -100 or between 0 and 100, exclusive.
3.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the code segment to the left. Asume that a is greater than zero.
Which of the following best described the value assign to b when the code segment is executed?
a
2 * a
A random integer between 0 and a-1, inclusive
A random integer between a and 2 * a, inclusive
A random integer between a and 2 * a - 1, inclusive
Answer explanation
The random method returns a value between 0.0,
inclusive, and 1.0, exclusive. Multiplying that value by a and
casting to an int produces a result between 0 and a - 1,
inclusive. The sum of a and a value between 0 and a - 1,
inclusive, is a value between a and 2 * a - 1, inclusive.
4.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the code segment:
String[] testOne = {"first", "day", "of", "spring"};
String[] resultOne = strArrMethod(testOne);
What are the contents of resultOne when the code segment has been executed?
{"day", "first", "of", "spring"}
{"of", "day", "first", "spring"}
{"of", "day", "of", "spring"}
{"of", "of", "of", "spring"}
{"spring", "first", day", "of"}
Answer explanation
The method assigns the shortest string that occurs in any element of arr between arr[n] and arr[arr.length -
1], inclusive, to result[n]. The shortest string found between arr[0] and arr[3] is "of", so result[0] is assigned the value "of". The shortest string found between arr[1] and arr[3] is also "of", so result[1] is also assigned the value "of". The same is true for the part of the array that begins at index 2 and ends at index 3, so result[2] is also assigned the value "of". In the last iteration of the outer for loop, there are no values to consider after arr[3], so result[3] is assigned the
value "spring".
5.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the code segments below:
String[] testTwo {"last", "day", "of", "the", "school", "year"};
String[] resultTwo = strArrMethod(testTwo);
How many times is the line labeled / / Line 12 in the strArrMethod executed as a result of
executing the code segment?
4 times
5 times
6 times
15 times
30 times
Answer explanation
Line 12 is executed each time the variable sm is updated
because a new smallest value is found. When j has the value 0, sm is updated for "day" and "of". When j has the value 1, sm is updated for "of". When j has the value 4, sm is updated for "year". When j has any of the values 2, 3, or 5, sm is not updated. Line 12 is executed four times.
6.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the following two code segments. Assume that the int variables m and n have been
properly declared and initialized and are both greater than 0.
Assume that the initial values of m and n are the same in code segment I as they are in code
segment II. Which of the following correctly compares the number of times that "A" and "B"
are printed when each code segment is executed?
"A" is printed m fewer times than "B"
"A" is printed n fewer times than "B"
"A" is printed m more times than "B"
"A" is printed n more times than "B"
"A" and "B" are printed the same number of times.
Answer explanation
There are m * n iterations of the for loop in code
segment I. In code segment II, the outer loop executes m times and the inner loop executes n - 1 times for each iteration of the outer
loop. There are m * n - m iterations of the inner loop in code segment II, so "A" is printed m more times than "B" is printed.
7.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
Consider the method to the left.
What, if anything, is returned by the method call abMethod ( "sing the song", "ng") ?
"si"
"si the so"
"si the song"
"sig the sog"
Nothing is returned because a StringindexOutOfBoundsException is thrown.
Answer explanation
The method abMethod(String a, String b)
removes all non-overlapping occurrences of string b from string a and returns the resulting String. It does this by repeatedly setting x to the index of an occurrence of b in a, then assigning a the result of the concatenation of the parts of a before and after the occurrence of b. The method call abMethod("sing the song", "ng") removes all occurrences of "ng" from "sing the song", returning "si the so".
Create a free account and access millions of resources
Similar Resources on Wayground
16 questions
For and While Loops in Python

Quiz
•
9th - 12th Grade
11 questions
APCSP Final Exam Coding Practice

Quiz
•
9th - 12th Grade
10 questions
APCSA - Unit 3

Quiz
•
9th - 12th Grade
15 questions
JavaScript and Graphics

Quiz
•
9th - 12th Grade
7 questions
Java Basics #2

Quiz
•
10th - 12th Grade
11 questions
Java Boolean Statements

Quiz
•
11th Grade
12 questions
Unit 5 Lists, Loops, & Traversals

Quiz
•
10th - 12th Grade
6 questions
Topic 6.1 Video 2

Quiz
•
11th Grade
Popular Resources on Wayground
55 questions
CHS Student Handbook 25-26

Quiz
•
9th Grade
18 questions
Writing Launch Day 1

Lesson
•
3rd Grade
10 questions
Chaffey

Quiz
•
9th - 12th Grade
15 questions
PRIDE

Quiz
•
6th - 8th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
22 questions
6-8 Digital Citizenship Review

Quiz
•
6th - 8th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
Discover more resources for Computers
55 questions
CHS Student Handbook 25-26

Quiz
•
9th Grade
10 questions
Chaffey

Quiz
•
9th - 12th Grade
40 questions
Algebra Review Topics

Quiz
•
9th - 12th Grade
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
19 questions
Handbook Overview

Lesson
•
9th - 12th Grade
20 questions
Lab Safety and Lab Equipment

Quiz
•
9th - 12th Grade
24 questions
Scientific method and variables review

Quiz
•
9th Grade
20 questions
Getting to know YOU icebreaker activity!

Quiz
•
6th - 12th Grade