

Unit 2 CSA Review
Presentation
•
Mathematics
•
12th Grade
•
Practice Problem
•
Hard
+4
Standards-aligned
Nichole Niebur
Used 1+ times
FREE Resource
13 Slides • 12 Questions
1
Unit 2: Using Objects Review
2
Multiple Choice
Consider the following code segment.
What is the value of dessert after the code segment has been executed?
strawpieberry
piestrawpieberry
strawpieberrypie
strawberry
piestrawberry
3
The second statement concatenates "straw", "pie", and "berry" and then appends the result to "pie".
Why?
4
Multiple Choice
Which of the following code segments can be used to set the value of the string str to "Good morning, sunshine!" ?
I only
II only
III only
II and III only
I, II, and III
5
All three code segments will produce the desired result.
Code segment I concatenates the strings "Good ", "morning,", and " sunshine!".
Code segment II creates the string variable str with initial value "Good" and uses the += string concatenation operator to append " morning, sunshine!" to it.
Code segment III creates the string variable str with initial value " morning, " and then concatenates "Good", str, and "sunshine!".
Why?
6
Multiple Choice
Consider the following code segment.
What is printed as a result of executing the code segment?
CS AP12
AP CS3
CSAP 12
APCS 12
APCS 3
7
The += operator used with values of type String appends the value on the right side of the operator to the value on the left side, so "AP" will remain at the beginning of the resulting string.
The + string concatenation operators are executed sequentially, so the code first appends "CS " to "AP", producing "APCS ". The operand 1 is treated as a string, so "1" is appended to "APCS ", producing "APCS 1". Finally, the operand 2 is treated as a string, so "2" is appended to "APCS 1", producing "APCS 12".
Why?
8
Multiple Choice
Consider the following code segment.
What is printed when the code segment is executed?
2
5
-1
2
5
2
2
6
-1
3
6
-1
-1
-1
2
9
The value of one.indexOf(two) is 2 because "C" occurs in "ABC123" at index 2.
The value of one.indexOf(three) is 5 because "3" occurs in "ABC123" at index 5.
The value of two.indexOf(one) is -1 because "ABC123" does not occur in "C".
Why?
10
Multiple Choice
Consider the following code segment.
What is printed when the code segment is executed?
epbe
epber
Sepbe
Seper
Sepber
11
The expression word.substring(0, 3) returns the first three characters of word, or "Sep".
The expression word.substring(word.length() - 3) returns the last three characters of word, or "ber".
The string "Sepber" is printed.
Why?
12
Multiple Choice
Consider the following code segment.
What, if anything, is printed when the code segment is executed?
Fdb
FGdebc
Gec
GHefcd
There is no output due to a compilation error.
13
The value of s1 is "ABCDEFGHI".
The value of s2 is "G".
The value of s3 is "abcdefghi".
The value of s4 is "e".
The value of s5 is "c".
The value of s2 + s4 + s5 is "Gec".
Why?
14
Multiple Choice
Consider the following calculate method and description.
What, if anything, is printed when the code segment is executed?
8.0
8.5
9
9.0
Nothing is printed because the code does not compile. The actual parameter d1 passed to calculate is a Double, but the formal parameter x is a double.
15
The variable d1, a Double with the value 7.5, is passed to the calculate method.
Since the formal parameter of calculate is a double, Java automatically unboxes the actual parameter.
The variable x is incremented by 1.5, resulting in 9.0, and that value is returned and printed.
Why?
16
Multiple Choice
Consider the following code segment.
What is printed when the code segment is executed?
8 8
8 10
10 10
16 10
16 18
17
The original variable is an Integer object for the integer 8. The first variable is an Integer object for the integer 16. The second variable is an Integer object for the integer 10. The expression first.intValue() + " " + second.intValue() is computed before it is printed. Since one of the terms in the addition is a string, all other terms in the addition are converted to strings. The value of the expression first.intValue() + " " + second.intValue() is the string "16 10".
Why?
18
Multiple Choice
Consider the following code segment.
Which of the following statements best describes the type and contents of num and n after the code segment executes?
num is Integer with value 15, & n is int with value 0.
num is Integer with value 15, & n is int with value 15.
num is Integer with value 15, & n is Integer with value 15.
num is int with value 15, & n is Integer with value 0.
num is int with value 15, & n is Integer with value 15.
19
An assignment cannot change a variable’s type, so n remains an int; it gets assigned the int value returned by num.intValue(), which is 15.
Why?
20
Multiple Choice
Which of the following expressions represents the shown equation, where x, k, and j are properly declared and initialized int variables?
Math.abs(k - j, Math.pow(x));
Math.abs(Math.pow(x), k - j);
Math.pow(x, Math.abs(k - j));
Math.pow(Math.abs(k - j), x);
Math.pow.abs(x, k - j));
21
The expression Math.abs(k - j) represents
and the expression Math.pow(x, Math.abs(k - j)) represents
Why?
22
Multiple Choice
The code segment below is intended to randomly print one of the values 2, 4, 6, or 8 with equal probability.
Which of the following can be used to replace /* missing code */ so that the code segment works as intended?
Math.random() * 4 + 1
Math.random() * 8
(int) (Math.random() * 4)
(int) (Math.random() * 4 + 1)
(int) (Math.random() * 8 + 1)
23
Math.random() returns a random double value greater than or equal to 0 and less than 1, so multiplying that value by 4 and adding 1 produces a random double value greater than or equal to 1 and less than 5. When a double value is cast to an int, its integer part is obtained. Casting Math.random() * 4 + 1 to an int assigns to val one of the int values from the set {1, 2, 3, 4}. Multiplying val by 2 produces one of the int values from the set{2, 4, 6, 8}, as intended.
Why?
24
Multiple Choice
Given the following code segment: double s;
Assume s has been properly initialized to a double value. The area of a square is its side length times itself.
Which of the following statements can be used to compute the area of a square whose side length is s units?
pow(s, 2);
s.pow(2);
Math.pow(s);
Math.pow(s, 2);
Math.pow(2, s);
25
The pow method is a static method defined in class Math, so the class name and the dot operator are needed to invoke this method.
This method call raises the first parameter, s, to the power given by the second parameter, 2, producing the square of s.
Why?
Unit 2: Using Objects Review
Show answer
Auto Play
Slide 1 / 25
SLIDE
Similar Resources on Wayground
21 questions
Parent Function Review
Presentation
•
11th - 12th Grade
23 questions
Matrix
Presentation
•
12th Grade
20 questions
Get Smart Plus 3 Topic 8 was/were
Presentation
•
1st - 4th Grade
20 questions
One Step Equations
Presentation
•
KG - University
19 questions
ECONOMICS TOPIC 1 LESSON 2
Presentation
•
12th Grade
20 questions
ACT Prep
Presentation
•
12th Grade
18 questions
JANJANG
Presentation
•
12th Grade
22 questions
5 Number Summary and Box Plot
Presentation
•
12th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Mathematics
18 questions
CCG Review - SA & V
Quiz
•
9th - 12th Grade
40 questions
8th Grade Math Review
Quiz
•
8th Grade - University
10 questions
11.1 Circumference and Arc Length
Quiz
•
9th - 12th Grade
20 questions
NC Math 3 EOC Review
Quiz
•
9th - 12th Grade
14 questions
HL Triangle Congruence
Presentation
•
9th - 12th Grade
16 questions
WDYE Review
Quiz
•
KG - University
33 questions
Algebraic Reasoning Final Exam 2026
Quiz
•
9th - 12th Grade
24 questions
5th Grade Math EOG Review
Quiz
•
KG - University