APCSA Exam Review

APCSA Exam Review

9th - 12th Grade

11 Qs

quiz-placeholder

Similar activities

Traversing Arrays

Traversing Arrays

10th - 12th Grade

6 Qs

Recursion Quizizz

Recursion Quizizz

9th - 12th Grade

10 Qs

Arrays

Arrays

10th - 12th Grade

10 Qs

29W Quiz 1 - PLTW

29W Quiz 1 - PLTW

8th - 12th Grade

15 Qs

19W Final Exam - PLTW

19W Final Exam - PLTW

9th - 12th Grade

15 Qs

AP CSA Unit 4 Review

AP CSA Unit 4 Review

11th Grade

13 Qs

String Methods

String Methods

9th - 12th Grade

10 Qs

Coding 1 U7

Coding 1 U7

9th Grade - University

15 Qs

APCSA Exam Review

APCSA Exam Review

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Created by

Daniel Geiter

Used 2+ times

FREE Resource

11 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

I Only

III Only

I and II Only

II and III only

I, II, and III

Answer explanation

In option I, the cast applies to the value 2, so floating-point

division is performed and the expression evaluates to 0.5 + 3, or 3.5. In option II, the cast applies to the result of the integer division 2 / 4, so the expression evaluates to 0.0 + 3, or 3.0. In option III, the cast applies to the sum of 3 and the result of the integer division 2 / 4, so the expression evaluates to (double) (0 + 3), or 3.0.

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the code segment to the left.

Which of the following statements assigns the same value to b2 as the code segment assigns to b1 for all values of num?

boolean b2 = (num > -100) && (num < 100);

boolean b2 = (num > -100) || (num < 100);

boolean b2 = (num < -100) || (num > 100);

boolean b2 = (num < -100) && (num > 0 || num < 100);

boolean b2 = (num < -100) || (num > 0 && num < 100);

Answer explanation

In the body of the first if clause in the code segment, b1

retains the value true if num is between 0 and 100, exclusive.

In the body of the else clause, b1 retains the value true if

num is less than -100. The statement assigns true to b2 if

num is less than -100 or between 0 and 100, exclusive.

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the code segment to the left. Asume that a is greater than zero.

Which of the following best described the value assign to b when the code segment is executed?

a

2 * a

A random integer between 0 and a-1, inclusive

A random integer between a and 2 * a, inclusive

A random integer between a and 2 * a - 1, inclusive

Answer explanation

The random method returns a value between 0.0,

inclusive, and 1.0, exclusive. Multiplying that value by a and

casting to an int produces a result between 0 and a - 1,

inclusive. The sum of a and a value between 0 and a - 1,

inclusive, is a value between a and 2 * a - 1, inclusive.

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the code segment:

String[] testOne = {"first", "day", "of", "spring"};

String[] resultOne = strArrMethod(testOne);

What are the contents of resultOne when the code segment has been executed?

{"day", "first", "of", "spring"}

{"of", "day", "first", "spring"}

{"of", "day", "of", "spring"}

{"of", "of", "of", "spring"}

{"spring", "first", day", "of"}

Answer explanation

The method assigns the shortest string that occurs in any element of arr between arr[n] and arr[arr.length -

1], inclusive, to result[n]. The shortest string found between arr[0] and arr[3] is "of", so result[0] is assigned the value "of". The shortest string found between arr[1] and arr[3] is also "of", so result[1] is also assigned the value "of". The same is true for the part of the array that begins at index 2 and ends at index 3, so result[2] is also assigned the value "of". In the last iteration of the outer for loop, there are no values to consider after arr[3], so result[3] is assigned the

value "spring".

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the code segments below:

String[] testTwo {"last", "day", "of", "the", "school", "year"};

String[] resultTwo = strArrMethod(testTwo);

How many times is the line labeled / / Line 12 in the strArrMethod executed as a result of

executing the code segment?

4 times

5 times

6 times

15 times

30 times

Answer explanation

Line 12 is executed each time the variable sm is updated

because a new smallest value is found. When j has the value 0, sm is updated for "day" and "of". When j has the value 1, sm is updated for "of". When j has the value 4, sm is updated for "year". When j has any of the values 2, 3, or 5, sm is not updated. Line 12 is executed four times.

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following two code segments. Assume that the int variables m and n have been

properly declared and initialized and are both greater than 0.

Assume that the initial values of m and n are the same in code segment I as they are in code

segment II. Which of the following correctly compares the number of times that "A" and "B"

are printed when each code segment is executed?

"A" is printed m fewer times than "B"

"A" is printed n fewer times than "B"

"A" is printed m more times than "B"

"A" is printed n more times than "B"

"A" and "B" are printed the same number of times.

Answer explanation

There are m * n iterations of the for loop in code

segment I. In code segment II, the outer loop executes m times and the inner loop executes n - 1 times for each iteration of the outer

loop. There are m * n - m iterations of the inner loop in code segment II, so "A" is printed m more times than "B" is printed.

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the method to the left.

What, if anything, is returned by the method call abMethod ( "sing the song", "ng") ?

"si"

"si the so"

"si the song"

"sig the sog"

Nothing is returned because a StringindexOutOfBoundsException is thrown.

Answer explanation

The method abMethod(String a, String b)

removes all non-overlapping occurrences of string b from string a and returns the resulting String. It does this by repeatedly setting x to the index of an occurrence of b in a, then assigning a the result of the concatenation of the parts of a before and after the occurrence of b. The method call abMethod("sing the song", "ng") removes all occurrences of "ng" from "sing the song", returning "si the so".

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?