Search Header Logo
Unit 2 CSA Review

Unit 2 CSA Review

Assessment

Presentation

Mathematics

12th Grade

Practice Problem

Hard

CCSS
6.NS.B.3, 6.EE.B.6, RF.3.3B

+4

Standards-aligned

Created by

Nichole Niebur

Used 1+ times

FREE Resource

13 Slides • 12 Questions

1

Unit 2: Using Objects Review

2

Multiple Choice

Question image

Consider the following code segment.
What is the value of dessert after the code segment has been executed?

1

strawpieberry

2

piestrawpieberry

3

strawpieberrypie

4

strawberry

5

piestrawberry

3

media

The second statement concatenates "straw", "pie", and "berry" and then appends the result to "pie".

Why?

4

Multiple Choice

Question image

Which of the following code segments can be used to set the value of the string str to "Good morning, sunshine!" ?

1

I only

2

II only

3

III only

4

II and III only

5

I, II, and III

5

media

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

Question image

Consider the following code segment.
What is printed as a result of executing the code segment?

1

CS AP12

2

AP CS3

3

CSAP 12

4

APCS 12

5

APCS 3

7

media

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

Question image

Consider the following code segment.
What is printed when the code segment is executed?

1

2
5
-1

2

2
5
2

3

2
6
-1

4

3
6
-1

5

-1
-1
2

9

media

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

Question image

Consider the following code segment.
What is printed when the code segment is executed?

1

epbe

2

epber

3

Sepbe

4

Seper

5

Sepber

11

media

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

Question image

Consider the following code segment.
What, if anything, is printed when the code segment is executed?

1

Fdb

2

FGdebc

3

Gec

4

GHefcd

5

There is no output due to a compilation error.

13

media

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

Question image

Consider the following calculate method and description.
What, if anything, is printed when the code segment is executed?

1

8.0

2

8.5

3

9

4

9.0

5

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

media

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

Question image

Consider the following code segment.
What is printed when the code segment is executed?

1

8 8

2

8 10

3

10 10

4

16 10

5

16 18

17

media

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

Question image

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?

1

num is Integer with value 15, & n is int with value 0.

2

num is Integer with value 15, & n is int with value 15.

3

num is Integer with value 15, & n is Integer with value 15.

4

num is int with value 15, & n is Integer with value 0.

5

num is int with value 15, & n is Integer with value 15.

19

media

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

Question image

Which of the following expressions represents the shown equation, where x, k, and j are properly declared and initialized int variables?

1

Math.abs(k - j, Math.pow(x));

2

Math.abs(Math.pow(x), k - j);

3

Math.pow(x, Math.abs(k - j));

4

Math.pow(Math.abs(k - j), x);

5

Math.pow.abs(x, k - j));

21

media

The expression Math.abs(k - j) represents
and the expression Math.pow(x, Math.abs(k - j)) represents

Why?

media
media

22

Multiple Choice

Question image

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?

1

Math.random() * 4 + 1

2

Math.random() * 8

3

(int) (Math.random() * 4)

4

(int) (Math.random() * 4 + 1)

5

(int) (Math.random() * 8 + 1)

23

media

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?

1

pow(s, 2);

2

s.pow(2);

3

Math.pow(s);

4

Math.pow(s, 2);

5

Math.pow(2, s);

25

media

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