wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

29W Quiz 1 - PLTW

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What will be the value of count as a result of executing the code segment?

a)

100

b)

161

c)

241

d)

341

2.

What value is stored in the variable count as a result of executing the code segment?

a)

16

b)

11

c)

71

d)

1

3.

Which of the following can be used to replace

/* missing condition */ so that the method will work as intended?

a)

count != 0

b)

num != 0

c)

num == 0

d)

count !=-= 0

4.

Which of the following can be used as a replacement for /* missing loop header */ so that the code segment prints out the string "1 2 3 4 "?

a)

while (k < 3)

b)

while (k < 4)

c)

while (k < 5)

d)

while (k <= 4)

5.

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

a)

A-

b)

AAA

c)

A

d)

AA

6.

Code segment 1 prints the sum of the integers from 1 through 30, inclusive. Which of the following best explains how the output changes from code segment 1 to code segment 2 ?

a)

Code segment 2 will print the sum of only the odd integers from 1 through 30, inclusive because it starts k at one, increments k by twos, and terminates when k exceeds 30.

b)

Code segment 1 will print the sum of only the odd integers from 1 through 50, inclusive because it starts k at one, increments k by twos, and terminates when k exceeds 30.

c)

Code segment 1 and 3 will print the sum of only the odd integers from 1 through 75, inclusive because it starts k at one, increments k by twos, and terminates when k exceeds 30.

d)

Code segment 2 will print the sum of only the odd integers from -5 through -30, inclusive because it starts k at one, increments k by twos, and terminates when k exceeds 30.

7.

Which of the following best explains how the output changes from code segment I to code segment II?

a)

The code segments print the same values but in a different order, because code segment III iterates from 11 to 15 and code segment II iterates from 15 to 21.

b)

The code segments print the same values but in a different order, because code segment II iterates from 1 to 5 and code segment II iterates from -5 to -1.

c)

The code segments print the same values but in a different order, because code segment I iterates from 2 to 6 and code segment II iterates from 5 to 1.

d)

The code segments print the same values but in a different order, because code segment I iterates from 1 to 5 and code segment II iterates from 5 to 1.

8.

Which of the following code segments will produce the same output as the code segment above?

a)

b)

c)

for (int k = 0; k <= 18; k += 2)

d)

for (int k = 0; k <= 8; k += -2)

9.

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

a)

B

b)

A & B

c)

C

d)

C & D

10.

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

a)

true

true =

true

b)

false

false

true

c)

true

false

true

d)

false =

false

true =

11.

What is printed as a result of executing this code segment?

a)

6

b)

5

c)

4

d)

3

12.

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

a)

eeSepC

b)

e C

c)

ci tm

d)

n c e P

13.

What value is returned as a result of the method call changeStr("12345") ?

a)

"13"

b)

23"

c)

"183"

d)

"53"

14.

Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?

a)

There will be one less value printed because the outer loop will iterate one fewer time.

b)

There will be six more values printed because the outer loop will iterate one or more additional times.

c)

There will be four more values printed because the outer loop will iterate one additional time.

d)

There will be no more values printed because the outer loop will iterate zero additional times.

15.

Which of the following best explains how changing the outer for loop header to for (int j = 0; j <= 3; j++) affects the output of the code segment?

a)

The string "Fun" will be printed more times because the outer loop will execute more times.

b)

The string "EHS" will be printed more times because the outer loop will execute more times.

c)

The string "String" will be printed more times because the outer loop will execute more times.

d)

The string "SISD" will be printed more times because the outer loop will execute more times.