AP CS A Java Iteration Practice 3/4

AP CS A Java Iteration Practice 3/4

9th - 12th Grade

5 Qs

quiz-placeholder

Similar activities

Part 2 - Python CodeHS Standards: Number Guessing Game

Part 2 - Python CodeHS Standards: Number Guessing Game

10th Grade

10 Qs

APCS Printing and objects

APCS Printing and objects

9th Grade - University

10 Qs

Loops

Loops

9th - 12th Grade

10 Qs

PYTHON BASIC 8 - 9

PYTHON BASIC 8 - 9

12th Grade

10 Qs

APCSA Units 7 & 8

APCSA Units 7 & 8

9th - 12th Grade

10 Qs

for and while loops quiz

for and while loops quiz

11th Grade

10 Qs

Strings

Strings

10th - 11th Grade

10 Qs

PYTHON (FOR LOOP)

PYTHON (FOR LOOP)

1st - 10th Grade

10 Qs

AP CS A Java Iteration Practice 3/4

AP CS A Java Iteration Practice 3/4

Assessment

Quiz

Computers

9th - 12th Grade

Hard

Created by

David Guy

Used 29+ times

FREE Resource

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Which of the following code segments produces the output "987654321" ?

Media Image
Media Image
Media Image
Media Image
Media Image

2.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

Consider the following methods.


Which of the following best describes the conditions under which methodOne and methodTwo return the same value?

When a and b are both even

When a and b are both odd

When a is even and b is odd

When a % b is equal to zero

When a % b is equal to one

3.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Media Image

Consider the following method definition. The method printAllCharacters is intended to print out every character in str, starting with the character at index 0.


The following statement is found in the same class as the printAllCharacters method.

printAllCharacters("ABCDEFG");

Which choice best describes the difference, if any, in the behavior of this statement that will result from changing x < str.length() to x <= str.length() in line 3 of the method?

The method call will print fewer characters than it did before the change because the loop will iterate fewer times.

The method call will print more characters than it did before the change because the loop will iterate more times.

The method call, which worked correctly before the change, will now cause a run-time error because it attempts to access a character at index 7 in a string whose last element is at index 6.

The method call, which worked correctly before the change, will now cause a run-time error because it attempts to access a character at index 8 in a string whose last element is at index 7.

The behavior of the code segment will remain unchanged.

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following code segments. Code segment 2 is a revision of code segment 1 in which the loop increment has been changed.


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 ?

Code segment 1 and code segment 2 will produce the same output.

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

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.

Code segment 2 will print the sum of only the even integers from 1 through 60, inclusive because it starts sum at zero, increments k by twos, and iterates 30 times.

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

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

Consider the following code segments.


Which of the code segments above will produce the following output?

1 4 7 10 13 16 19

I only

II only

I and II only

II and III only

I, II, and III