Verityprep
Question Bank · Unit 2

AP® Computer Science A Selection and Iteration Multiple Choice Questions

Work through AP Computer Science A multiple-choice 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: Boolean Expressions Clear filter

Questions 161–170 of 316
  1. 161
  2. 162
  3. 163
  4. 164
  5. 165
  6. 166
  7. 167
  8. 168
  9. 169
  10. 170

Question 161

Multiple choice Boolean Expressions
Consider the following method, which increments a counter and returns false. private int count = 0; public boolean check() { count++; return false; } Consider…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 162

Multiple choice Boolean Expressions
Consider the following boolean expression, where x is an int variable. (x > 0 && x < 10)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 163

Multiple choice Boolean Expressions
Consider the following boolean expression, where a, b, and c are int variables. a > 0…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 164

Multiple choice Boolean Expressions
Consider the following method. public static String grade(int score) { String result = ""; if (score >= 90) { result = "A"; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 165

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 166

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 167

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 168

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 169

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 170

Multiple choice Boolean Expressions
Consider the following code segment, where arr is a non-null int array (possibly empty).
int i = 0;
while (i < arr.length && arr[i] != 0)
{
    i = i + 1;
}
Which of the following statements about the loop is true for every valid value of arr?
Pick an answer, then check it. The solution opens in a window.
Question 161 of 316
Page 17 of 32