AP Computer Science A Unit 3 Progress Check: MCQ
This expression appears to compare two relational expressions, but Java does not support chaining relational operators like this directly. Instead, it evaluates a < b to true and c < b to true, and then attempts to evaluate true != true, which is false.
Consider the following variable declarations and initializations.
int a = 2;
int b = 6;
int c = 3;
Which of the following expressions evaluates to false ?
D. a < b != c < b
Key Terms
Consider the following variable declarations and initializations.
int a = 2;
int b = 6;
int c = 3;
Which of the following expressions evaluates to false ?
D. a < b != c < b
Consider the following code segment.
boolean a = true;
boolean b = false;
System.out.print((a == !b) != false);
What is printed as a result of executing this code segment?
B. true
Consider the following expression.
(3 + 4 == 5) != (3 + 4 >= 5)
What value, if any, does the expression evaluate to?
A. true
Consider the following code segment.
int quant = 20;
int unitPrice = 4;
int ship = 8;
int total;
if (quant > 10)
{
unitPrice = 3;
}
if (quant > 20)
{
ship = 0;
}
total = quant * unitPrice + ship;
What is the value of total after this code segment has been executed?
C. 68
Consider the following code segment.
int a = 1;
int b = 0;
int c = -1;
if ((b + 1) == a)
{
b++;
c += b;
}
if (c == a)
{
a--;
b = 4;
}
What are the values of a, b, and c after this code segment has been executed?
D. a = 1, b = 1, and c = 0
Consider the following code segment.
int m = 8;
int n = 3;
if (m + n > 10)
{
System.out.print(m + n);
}
if (m - n > 0)
{
System.out.print(m - n);
}
What, if anything, is printed as a result of executing the code segment?
D. 115
Study Tips
- Press F to enter focus mode for distraction-free studying
- Review cards regularly to improve retention
- Try to recall the answer before flipping the card
- Share this deck with friends to study together
Term | Definition |
---|---|
Consider the following variable declarations and initializations. | D. a < b != c < b |
Consider the following code segment. | B. true |
Consider the following expression. | A. true |
Consider the following code segment. | C. 68 |
Consider the following code segment. | D. a = 1, b = 1, and c = 0 |
Consider the following code segment. | D. 115 |
In the code segment below, the int variable temp represents a temperature in degrees Fahrenheit. The code segment is intended to print a string based on the value of temp. The following table shows the string that should be printed for different temperature ranges. | A. I only |
Consider the following code segment, which is intended to set the Boolean variable inRange to true if the integer value num is greater than min value and less than max value. Otherwise inRange is set to false. Assume that inRange, num, min, and max have been properly declared and initialized. | D. num = 50, min = 50, max = 50 |
Assume that the int variables a, b, c, and low have been properly declared and initialized. The code segment below is intended to print the sum of the greatest two of the three values but does not work in some cases. | E. a = 3, b = 2, c = 1 |
Consider the following code segment. | C. C |
Consider the following code segment in which the int variables a and b have been properly declared and initialized. | E. |
Consider the following two code segments. Assume that variables x and y have been declared as int variables and have been assigned integer values. | A. Code segment I and code segment II produce the same output for all values of x and y. |
Consider the following two code segments, which are both intended to determine the longest of the three strings "pea", "pear", and "pearl" that occur in String str. For example, if str has the value "the pear in the bowl", the code segments should both print "pear" and if str has the value "the pea and the pearl", the code segments should both print "pearl". Assume that str contains at least one instance of "pea". | E. Code segment II produces correct output for all values of str, but code segment I produces correct output only for values of str that contain "pea" but not "pear". |
The following code segment prints one or more characters based on the values of boolean variables b1 and b2. Assume that b1 and b2 have been properly declared and initialized. | C. AD |
Consider the following code segment, which uses properly declared and initialized int variables x and y and the String variable result. | D. def |
Consider the following code segment. | C. true false false |
In the following expression, j, k, and m are properly declared and initialized int variables. | B. (j != k) || (k <= m) |
In the following expression, sunny and windy are properly declared and initialized boolean variables. | C. !(sunny || windy) |
In the following expression, sweet, salty, and sour are properly declared and initialized boolean variables. | B. (sweet && salty) || (sweet && sour) |
Consider the following code segment. | B. true true false |
Consider the following code segment. | B. true false |