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: Boolean Expressions Clear filter

Questions 191–200 of 357
  1. 191
  2. 192
  3. 193
  4. 194
  5. 195
  6. 196
  7. 197
  8. 198
  9. 199
  10. 200

Question 191

Multiple choice Boolean Expressions
Consider the following code segment.
int c = 0;
for (int i = 0; i < 5; i++)
{
    for (int j = 0; j < 5; j++)
    {
        if (i + j < 5)
        {
            c++;
        }
    }
}
System.out.println(c);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 192

Multiple choice Boolean Expressions
Consider the boolean expression (a > b || b > c) && !(a > c). Which of the following sets of values for a, b, and c causes the expression to evaluate to true?
Pick an answer, then check it. The solution opens in a window.

Question 193

Multiple choice Boolean Expressions
Consider the boolean expression below, where x and y are int variables. !(x > 0 &&…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 194

Multiple choice Boolean Expressions
Consider the following method and code segment. public static int inc(int[] a) { a[0] = a[0] + 1; return a[0]; } int[] a = { 0 }; if (a[0] > 0 || inc(a) > 0) {…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 195

Multiple choice Boolean Expressions
Consider the following boolean expression, where x and y are int variables.
(x > 0 && y > 0) || (x > 0 && y <= 0)
Which of the following expressions is equivalent for all values of x and y?
Pick an answer, then check it. The solution opens in a window.

Question 196

Multiple choice Boolean Expressions
Consider the following code segment.
int age = 25;
if (age >= 18 && age < 65)
{
    System.out.print("adult ");
}
if (age < 18 || age >= 65)
{
    System.out.print("special ");
}
if (!(age >= 18) || !(age < 65))
{
    System.out.print("edge ");
}
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 197

Multiple choice Boolean Expressions
Consider the boolean expression below, where a, b, and c are int variables. !(a <= b)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 198

Multiple choice Boolean Expressions
Consider the following method.
public static String g(int n)
{
    if (n < 10)
    {
        return "" + n;
    }
    return (n % 10) + g(n / 10);
}
What is returned by the call g(1423)?
Pick an answer, then check it. The solution opens in a window.

Question 199

Multiple choice Boolean Expressions
Consider the following boolean expression, where a and b are int variables. !(a >= 10…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 200

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 191 of 357
Page 20 of 36