apcsa_mock_exam_.pdf
apcsa_mock_exam_.pdf
int a = 3 + 2 * 3;
int b = 4 + 3 / 2;
int c = 7 % 4 + 3;
double d = a + b + c;
What is the value of d after the code segment is executed? 20.0
2. Consider the following code segment. Assume num is a properly declared and initialized int variable.
if (num > 0) {
if (num % 2 == 0) {
System.out.println("A"); }
Else {
System.out.println("B"); } }
Which of the following best describes the result of executing the code segment? When num is a positive even
integer, "A" is printed; when num is a positive odd integer, "B" is printed; otherwise, nothing is printed.
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
7. Consider the following code segment.
int num = /* initial value not shown */;
boolean b1 = true;
if (num > 0){
if (num >= 100){
b1 = false;}}
Else {
if (num >= -100){
b1 = false; }}
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 > 0 && num < 100);
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
11. Which of the following code segments produces the output "987654321"?
C.
int num = 10;
while (num > 1)
{
System.out.print(num);
num --;
}
12. Consider the following class definitions.
public class Person
{
private String name;
public String getName()
{ return name; }
}
public class Book
{
private String author;
private String title;
private Person borrower;
public Book(String a, String t)
{
author = a;
title = t;
borrower = null;
}
public void printDetails()
{
System.out.print("Author: " + author + " Title: " + title);
if ( /* missing condition */ )
{
System.out.println(" Borrower: " + borrower.getName());
}
}
public void setBorrower(Person b)
{ borrower = b; }
}
Which of the following can replace /* missing condition */ so that the printDetails method CANNOT cause a
run-time error?
2. borrower != null
13. Assume that a, b, and c are boolean variables that have been properly declared and initialized. Which of the
following boolean expressions is equivalent to !(a && b) || c ? E.
14. The following categories are used by some researchers to categorize zip codes as urban, suburban, or rural
based on population density.
● An urban zip code is a zip code with more than 3,000 people per square mile.
● A suburban zip code is a zip code with between 1,000 and 3,000 people, inclusive, per square mile.
● A rural zip code is a zip code with fewer than 1,000 people per square mile.
Consider the following method, which is intended to categorize a zip code as urban, suburban, or rural based
on the population density of the area included in the zip code. I & III only
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
15. Consider the following code segment. Assume that a is greater than zero.
int a = /* value not shown */;
int b = a + (int) (Math.random() * a);
Which of the following best describes the value assigned to b when the code segment is executed? E. A
random integer between a and 2 * a - 1, inclusive
18. Which of the following can replace /* missing loop header */ so the method countPeaks works as
intended? E. int p =1; p< data.length -1; p++
20. The following code segment is intended to store in maxPages the greatest number of pages found in any
Book object in the array bookArr.
Book[] bookArr = { /* initial values not shown */ };
int maxPages = bookArr[0].getPages();
for (Book b : bookArr)
{
/* missing code */
}
Which of the following can replace /* missing code */ so the code segment works as intended?
B. if (b.getPages() > maxPages)
{
maxPages = b.getPages();
}
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
22. Consider the following code segment.
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? A. 4 times
23. When executed, the code segment should produce the following output.
12345678
Which of the following code segments can replace /* missing code */ so that the rowMajor method works as
intended?
24. The following code segment appears in a class other than SomeClass.
SomeClass first = new SomeClass(10);
SomeClass second = new SomeClass(20);
SomeClass third = new SomeClass(30);
first.incrementY();
second.incrementY(10);
System.out.println(third.getY());
What is printed as a result of executing the code segment if the code segment is the first use of a SomeClass
object? D. 14
26. 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? C. "A" is printed m more times than "B".
27. Consider the following statement. Assume that a and b are properly declared and initialized boolean
variables.
boolean c = (a && b) || (!a && b);
Under which of the following conditions will c be assigned the value false? E. When b has the value false
28. What, if anything, is returned by the method call abMethod("sing the song", "ng")?
B. "si the so"
30. Which of the following code segments can replace /* missing code */ so that the Square class constructor
initializes the Rectangle class instance variables height and width to x?
B. super(x);
31. Which of the following code segments counts the number of negative values found in nums and stores the
count in counter? A. 1 Only
32. The following code segment appears in a class other than ClassA or ClassB.
ClassA obj = new ClassB();
obj.showValue();
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
What, if anything, is printed when the code segment is executed? B. B
34. As an example, if the method is called with an ArrayList containing the values [5, 2, 10, 20, 16] and the
parameter key has the value 5, then numList should contain [2, 16] at the end of the method and an ArrayList
containing [5, 10, 20] should be returned.
Which of the following best explains why the method does not always work as intended? E. The method skips
some elements of numList during the traversal.
35. Consider the mode method, which is intended to return the most frequently occurring value (mode) in its
int[] parameter arr. For example, if the parameter of the mode method has the contents {6, 5, 1, 5, 2, 6, 5}, then
the method is intended to return 5.
A. Arr[j] == arr[k] & valCount > modeCount
36. Which of the following best describes the conditions under which methodOne and methodTwo return the
same value? D. When a % b is equal to zero.
37. Consider the following code segment. Assume that num3 > num2 > 0. Which of the following best
describes the contents of num1 as a result of executing the code segment? E. The sum of all integers from
num2 to num3 - 1, inclusive
38. Which of the following code segments can replace /* missing code */ so the getTotal method works as
intended? D. I and II
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
Which of the following method calls will return true? D. recurMethod("edcba")
40. Which of the following best explains the difference, if any, in the behavior of the code segment that will
result from removing the message method from class A? A. The statement in line 3 will cause a compiler error
because the message method for obj1 cannot be found.
FRQ
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
3. a) Public void addReview(Product Review prodReview) {
reviewList.add(prodReview);
This study source was downloaded by 100000806476756 from CourseHero.com on 04-23-2025 12:33:21 GMT -05:00
https://www.coursehero.com/file/161954582/apcsa-mock-exam-pdf/
Powered by TCPDF (www.tcpdf.org)