
AP CS A Test #2

Quiz
•
Computers
•
9th - 12th Grade
•
Hard
Used 1+ times
FREE Resource
12 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following code segment:
int x = 3;
double y = Math.pow(x, 3);
double z = Math.sqrt(y - Math.abs(-2));
What is the value of z after this code segment has executed?
0.0
3.0
5.0
9.0
10.0
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What does the expression "Nomnomnom yummy turkey".indexOf("Thank") evaluate to?
Thank
Nomnomnom
turkey
-1
0
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following code segment.
int x = /* some integer value */ ;
int y = /* some integer value */ ;
boolean result = (x < y);
result = ( (x >= y) && !result );
Which of the following best describes the conditions under which the value of result will be true after the code segment is executed?
Only when x < y
Only when x >= y
Only when x and y are equal
The value will always be true .
The value will always be false .
4.
MULTIPLE CHOICE QUESTION
5 mins • 1 pt
Consider the following instance variables and incomplete method that are part of a class that represents an item. The variables years and months are used to represent the age of the item, and the value for months is always between 0 and 11, inclusive. Method updateAge is used to update these variables based on the parameter extraMonths that represents the number of months to be added to the age.
private int years;
private int months; // 0 <= months <= 11
public void updateAge(int extraMonths)
{
/* body of updateAge */
}
Which of the following code segments shown below could be used to replace /* body of updateAge */ so that the method will work as intended?
I int yrs = extraMonths % 12;
int mos = extraMonths / 12;
years = years + yrs;
months = months + mos;
II int totalMonths = years * 12 + months + extraMonths;
years = totalMonths / 12;
months = totalMonths % 12;
III int totalMonths = months + extraMonths;
years = years + totalMonths / 12;
months = totalMonths % 12;
I only
II only
III only
I and II only
II and III
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following method.
public static void conditionalTest(int a, int b)
{
if ((a > 0) && (b > 0))
{
if (a > b)
System.out.println("A");
else
System.out.println("B");
}
else if ((b < 0) || (a < 0))
System.out.println("C");
else
System.out.println("D");
}
What is printed as a result of the call conditionalTest(3, -2) ?
A
B
C
D
Nothing is printed
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Consider the following static method.
public static int calculate(int x)
{
x = x + x;
x = x + x;
x = x + x;
return x;
}
Which of the following can be used to replace the body of calculate so that the modified version of calculate will return the same result as the original version for all possible values of x ?
return 3 + x;
return 3 * x;
return 4 * x;
return 6 * x;
return 8 * x;
7.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Assume that a and b are boolean variables and have been properly initialized.
(a && b) || !(a && b)
The result of evaluating the expression above is best described as:
Always true
Always false
true only when a is true and b is true
true only when a and b have the same value
true only when a and b have different values
Create a free account and access millions of resources
Similar Resources on Wayground
14 questions
Limbajul de programare C++ ” INSTRUCȚIUNEA IF”

Quiz
•
10th Grade
14 questions
C++ - Loops and Random Numbers

Quiz
•
9th - 12th Grade
15 questions
Area and Arrays

Quiz
•
10th - 12th Grade
15 questions
Большое Повторение C#

Quiz
•
5th Grade - University
16 questions
CSA Unit 3 Review

Quiz
•
10th - 12th Grade
10 questions
Variables in C++

Quiz
•
9th - 12th Grade
13 questions
String Manipulation

Quiz
•
9th - 11th Grade
15 questions
С++ введение

Quiz
•
10th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
10 questions
Exploring Digital Citizenship Essentials

Interactive video
•
6th - 10th Grade
10 questions
1.2 OSI & TCP IP Models Quiz

Quiz
•
10th Grade
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
30 questions
Introduction to Computers

Quiz
•
8th - 9th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
20 questions
Hardware vs. Software Quiz

Quiz
•
7th - 10th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade