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?
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
15 questions
Java Math
Quiz
•
9th - 12th Grade
10 questions
STRING HANDLING
Quiz
•
10th Grade
17 questions
"switch" Java Statement - 1
Quiz
•
9th - 10th Grade
12 questions
Compound Operators in Java
Quiz
•
9th - 12th Grade
11 questions
Casting in Java
Quiz
•
9th - 12th Grade
16 questions
Arithmetic Types Declare Initialize Relation Logical Ops
Quiz
•
9th Grade - University
10 questions
Quiz 15 - Array Basics
Quiz
•
11th Grade
15 questions
Array
Quiz
•
10th - 12th Grade
15 questions
Multiplication Facts
Quiz
•
4th Grade
25 questions
SS Combined Advisory Quiz
Quiz
•
6th - 8th Grade
40 questions
Week 4 Student In Class Practice Set
Quiz
•
9th - 12th Grade
40 questions
SOL: ILE DNA Tech, Gen, Evol 2025
Quiz
•
9th - 12th Grade
20 questions
NC Universities (R2H)
Quiz
•
9th - 12th Grade
15 questions
June Review Quiz
Quiz
•
Professional Development
20 questions
Congruent and Similar Triangles
Quiz
•
8th Grade
25 questions
Triangle Inequalities
Quiz
•
10th - 12th Grade
40 questions
Week 4 Student In Class Practice Set
Quiz
•
9th - 12th Grade
40 questions
SOL: ILE DNA Tech, Gen, Evol 2025
Quiz
•
9th - 12th Grade
20 questions
NC Universities (R2H)
Quiz
•
9th - 12th Grade
25 questions
Triangle Inequalities
Quiz
•
10th - 12th Grade
10 questions
Right Triangles: Pythagorean Theorem and Trig
Quiz
•
11th Grade
46 questions
Biology Semester 1 Review
Quiz
•
10th Grade
24 questions
LSO - Virus, Bacteria, Classification - sol review 2025
Quiz
•
9th Grade
65 questions
MegaQuiz v2 2025
Quiz
•
9th - 12th Grade