Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Practice Questions

Work through AP Computer Science A practice questions on Selection and Iteration, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Iteration Clear filter

Questions 341–350 of 383
  1. 341
  2. 342
  3. 343
  4. 344
  5. 345
  6. 346
  7. 347
  8. 348
  9. 349
  10. 350

Question 341

Multiple choice Iteration
Which replacement for the condition produces the required four-line output shown in the comment? Leading spaces are significant. /* Required output: * ** ***…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 342

Multiple choice Iteration
Which expression produces the required centered shape shown in the comment? Leading spaces are significant. /* Required output: * *** ***** */ for (int row = 1;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 343

Multiple choice Iteration
Which replacement for the condition produces the required output shown in the comment? /* Required output: *-*- -*-* *-*- */ for (int row = 0; row < 3;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 344

Multiple choice Iteration
Which output is produced? for (int row = 1; row <= 3; row++) { for (int col = 1; col <= 7; col++) { if (col…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 345

Multiple choice Iteration
Which single edit produces the required output shown in the comment, with no extra blank lines? /* Required output: ** **** ****** */…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 346

Multiple choice Iteration
Version I uses row == 0 || col == 0 as the condition. Version II uses row == 0 || col == n - 1. Which offered nonnegative int n is the smallest size for which…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 347

Multiple choice Iteration
For every int n from 0 through 8 inclusive, the loop should leave total equal to n * n. Which…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 348

Multiple choice Iteration
The code is intended to count the nonzero decimal digits of a positive int number. Which offered initial value…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 349

Multiple choice Iteration
Each version starts with int x = 0 and runs the displayed body four times. Version II changes the second if to else if. What are the final x…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 350

Multiple choice Iteration
Each version starts with int result = 3. For how many int values of n from 0 through 4 inclusive do the versions finish with the same…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 341 of 383
Page 35 of 39