

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
18 questions
Basic Probability
Presentation
•
11th - 12th Grade
21 questions
Renting an Apartment
Presentation
•
12th Grade
20 questions
Graphing Polynomials
Presentation
•
12th Grade
20 questions
Graphing Polynomials
Presentation
•
11th Grade
20 questions
Reading Graphs
Presentation
•
11th Grade
20 questions
Negative Exponents
Presentation
•
12th Grade
17 questions
Least Squares Regression Line Practice
Presentation
•
12th Grade
20 questions
5.3 Dot Plots
Presentation
•
11th - 12th Grade
Popular Resources on Wayground
6 questions
Secondary Safety Quiz
Presentation
•
9th - 12th Grade
10 questions
MyPath Diagnostic Overview
Presentation
•
6th - 8th Grade
20 questions
Lab Safety Quiz
Quiz
•
6th Grade
21 questions
Continents and Oceans
Quiz
•
6th Grade
20 questions
Adding and Subtracting Decimals
Quiz
•
5th Grade
20 questions
Parts of Speech
Quiz
•
5th Grade
16 questions
Subject & Predicate
Quiz
•
5th Grade
21 questions
Lab Safety
Quiz
•
10th Grade
Discover more resources for Mathematics
19 questions
Classify Types of Real Numbers
Quiz
•
9th - 12th Grade
10 questions
1.1 (c) Area & Perimeter Polynomials
Quiz
•
9th - 12th Grade
18 questions
Identify Points, Lines, and Planes
Quiz
•
9th - 12th Grade
25 questions
Measure Lengths and Angles
Quiz
•
9th - 12th Grade
10 questions
Parent Functions and Transformations
Quiz
•
10th - 12th Grade
24 questions
Points, Lines, Planes Review
Quiz
•
9th - 12th Grade
15 questions
Combine Like Terms
Quiz
•
9th - 12th Grade
20 questions
Solve Basic Algebraic Equations
Quiz
•
9th - 12th Grade