AP Computer Science A Unit 3 Progress Check: MCQ Exam
Consider the following variable declarations and initializations.
int a = 2;
int b = 6;
int c = 3;
Which of the following expressions evaluates to false ? - Answer -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? - Answer -B. true
Consider the following expression.
(3 + 4 == 5) != (3 + 4 >= 5)
What value, if any, does the expression evaluate to? - Answer -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? - Answer -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? - Answer -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? - Answer -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.
Temperature RangeString to Print31 and below"cold"32-50"cool"51-70"moderate" 71 and above"warm"
String weather;
if (temp <= 31)
{
weather = "cold";
}
else
{
weather = "cool";
}
if (temp >= 51)
{
weather = "moderate";
}
Consider the following variable declarations and initializations.
int a = 2;
int b = 6;
int c = 3;
Which of the following expressions evaluates to false ? - Answer -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? - Answer -B. true
Consider the following expression.
(3 + 4 == 5) != (3 + 4 >= 5)
What value, if any, does the expression evaluate to? - Answer -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? - Answer -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? - Answer -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? - Answer -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.
Temperature RangeString to Print31 and below"cold"32-50"cool"51-70"moderate" 71 and above"warm"
String weather;
if (temp <= 31)
{
weather = "cold";
}
else
{
weather = "cool";
}
if (temp >= 51)
{
weather = "moderate";
}