WorksheetsAP CSA Unit 3 Boolean Expressions
Total questions: 30
Worksheet time: 15mins
Consider the code assuming that a b c and d are ints, which of the following is an example of short circuit evaluation?
if a > b is true it doesn't evaluate c == d
if c == d is false it evaluates a > b
if a > b is false it doesn't evaluate c == d
if c == d is true it doesn't evaluate a > b
Just before exiting this program, what are the values of the instance variable value of MultiplyObjects a, b and c?
5, 10, 20
40, 40, 40
40, 10, 40
10, 10, 20
The boolean expression (A || B) && A is true
whenever A is true
whenever B is true
whenever either A is true or B is true
whenever both A is true and B is true
In all cases
The boolean expression (A && B) && B is true
whenever A is true
whenever B is true
whenever either a is true or B is true
whenever both A is true and B is true
In all cases
For what values of n with this code segment generate output?
for all values of n
for all even values of n
for all values of n that are multiples of 3
for all values of n that are multiples of 6
for all values of n that are either a multiple of 2 or a multiple of 3.
What is printed as a result of executing the program?
10 20
10 20
10 20
20 10
10 10
20 20
20 20
20 20
There is no output displayed.
For what values of n will the code segment generate output?
For all values of n
For all values of n in the range [20 .. 100]
For all values of n in the range [51 .. 99]
For all values of n NOT in the range of [50 .. 100]
For al values of n NOT in the range of [51 .. 99]
For what values of n will this code segment generate output?
for all values of n
for all values of n which are 100 or greater
for all values of n which are 100 or less
for all values of n NOT equal to 100
for n == 100 only
What kind of statement groups several statements together?
simple
boolean
block
condition
Which if condition correctly checks whether there are sufficient funds in the bank account to withdraw "amount"?
if (balance = amount)
if {balance >= amount}
if [balance >= amount]
if (balance >= amount)
Which java statement correctly implements the following pseudocode: display "A" when the student's grade is higher than 90 (inclusive)
if (studentGrade = 90)
if (studentGrade > 90)
if (studentGrade >= 90)
if (studentGrade < 90)
Which statement is true about the following code fragment involving a conditional?
Never prints out "Insufficient funds".
Does not compile.
Only prints out "Insufficient funds" when amount > balance
Always prints out "Insufficient funds"
Consider the following code, assuming grade is an int:
Which of the following will always produce the same result as the code above, regardless of the value of grade? (multiple correct answers)
What is output by the following code?
11
31
15
error
Consider the following incomplete code segment.
Consider the following potential replacements for /* missing code */ . Which of these replacements will cause
the code segment to always print false ? Assume that Math is imported correctly into our program.
(int)(Math.random() * 10) + 20
(int)(Math.random() * 10) + 25
(int)(Math.random() * 10) + 30
(int)(Math.random() + 30)
Which condition should be used to test whether the contents of two strings referenced by string1 and string2 have the same value?
(string1.equals(string2))
(String.equals(string1, string2))
(string1 == string2)
(Equals(string1, string2))
Which String method compares strings in dictionary (lexigraphical) order?
compare
compareDictionary
equals
compareTo
If string1 and string2 are equal, then string1.compareTo(string2)___________. Fill in the blank with the correct option.
.equals(0)
== 0
== true
== null
Which choice denotes an empty string?
empty
""
nil
null
Which operator or method tests whether two object references are identical?
==
equals
=
identity
Which operator or method should you use to determine whether the contents of objects have the same value?
==
equals
=
same
Which of the following statements determines whether a person is ineligible for a junior or senior discount, assuming that a person is eligible for the discount if they are younger than 18 or older than 62?
age >= 18 && age > 62
age >= 18 || age <= 62
age <= 18 || age >= 62
age >= 18 && age <= 62
Which of the following conditions tests whether x is NOT between 1 and 10 (inclusive)?
10 < x || x < 1
!(1 <= x <= 10)
1 <= x || x <= 10
1 > x && x <= 10
The following truth table matches which boolean condition?
A && ( A || B )
!A && ( A || !B )
A && ( A && B )
A || ( A || B )
A weather app records the current temperature to the nearest degree Fahrenheit using an int variable temp.
The app also uses a String variable tempAdj to store an adjective based on the value of temp which will be used
in a short written summary of the current weather. The values of tempAdj are determined as follows:
Which of the following code segments will correctly set the value of tempAdj for any given value of temp? (Multiple correct answers)
Consider the following code, assuming word is a string:
What does the code do?
Tests if the String word contains only
non-letter characters.
Tests if the String word contains only
upper-case letters.
Tests if the String word contains only
numeric values.
Tests if the String word contains
only lower-case letters.
Assume that x and y are boolean variables and have been properly initialized.
What will be output if the value of x is true and the value of y is false:
One
Two
Three
OneTwo
What is output by the following code segment? Assume a Triangle class exists and each triangle is correctly
created.
equal
not equal
equalnot equal
Nothing, there is an error
What is the value of the variable condition in the following code?
true
The code has a syntax error and will not compile.
false
The code compiles but has a logic error.
What is the value of condition assuming that two circles are considered equal if they have the same radius value? (The value in the parenthesis is the radius of the circle.)
false
true
The code compiles but has a logic error.
The code has a syntax error and will not compile.
