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.

Questions 421–430 of 740
  1. 421
  2. 422
  3. 423
  4. 424
  5. 425
  6. 426
  7. 427
  8. 428
  9. 429
  10. 430

Question 421

Multiple choice Boolean Expressions
Consider the following class. public class Logger { private int calls; public Logger() { calls = 0; } public boolean ping() { calls = calls + 1; return true; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 422

Multiple choice Boolean Expressions
Consider the following method. public static String tier(int score) { if (score >= 90) { return "gold"; } else if (score >=…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 423

Multiple choice Iteration
Consider the following code segment. int sum = 0; for (int i = 5; i <= 20; i = i + 3) { if (i % 2…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 424

Multiple choice Boolean Expressions
Consider the boolean expression below, where a, b, and c are boolean variables.
!(a && (b || !c))
Which of the following is logically equivalent to the expression above?
Pick an answer, then check it. The solution opens in a window.

Question 425

Multiple choice Iteration
Consider the following code segment.
int n = 100;
int steps = 0;
while (n > 1)
{
    if (n % 2 == 0)
    {
        n = n / 2;
    }
    else
    {
        n = n - 1;
    }
    steps = steps + 1;
}
System.out.println(steps);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 426

Multiple choice Iteration
Consider the following code segment. String s = ""; for (int r = 1; r <= 3; r++) { for (int c = 0; c < r;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 427

Multiple choice Iteration
Consider the following code segment. int p = 1; for (int i = 1; i <= 5; i++) { if (i % 2 ==…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 428

Multiple choice Boolean Expressions
Consider the following method.
public static String rate(int n)
{
    if (n < 0 || n > 100)
    {
        return "invalid";
    }
    if (n < 25)
    {
        return "low";
    }
    if (n < 75)
    {
        return "mid";
    }
    return "high";
}
For how many integer values of n in the range \(0 \leq n \leq 100\) does rate(n) return "mid"?
Pick an answer, then check it. The solution opens in a window.

Question 429

Multiple choice Boolean Expressions
Consider the following expression, where a and b are int variables. (a > 0 && b > 0) || (a < 0…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 430

Multiple choice Iteration
Consider the following code segment. int n = 1; int total = 0; while (n < 100) { total = total + n; if (n < 10)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 421 of 740
Page 43 of 74