Chapter 3 Book Quiz Flashcards
The if statement is an example of a .
a. sequence structure
b. decision structure
c. pathway structure
d. class structure
b. decision structure
Explanation: The if statement is used to make decisions based on a boolean condition, which is why it is classified as a decision structure.
This type of expression has a value of either true or false .
a. binary expression
b. decision expression
c. unconditional expression
d. boolean expression
d. boolean expression
Explanation: A boolean expression is one that evaluates to either true or false.
> , < , and == are .
a. relational operators
b. logical operators
c. conditional operators
d. ternary operators
a. relational operators
Explanation: Relational operators compare two values and return a boolean result, such as >, <, and ==.
&& , || , and ! are .
a. relational operators
b. logical operators
c. conditional operators
d. ternary operators
b. logical operators
Explanation: These operators (&&, ||, and !) are used to combine or negate boolean expressions in Java.
This is an empty statement that does nothing.
a. missing statement
b. virtual statement
c. null statement
d. conditional statement
c. null statement
Explanation: A null statement, also called an empty statement, does nothing and is represented by a semicolon ;.
To create a block of statements, you enclose the statements in these.
a. parentheses ()
b. square brackets []
c. angled brackets <>
d. braces {}
d. braces {}
Explanation: A block of code (or a compound statement) is enclosed in braces {}.
This is a boolean variable that signals when some condition exists in the program.
a. flag
b. signal
c. sentinel
d. siren
a. flag
Explanation: A flag is a boolean variable used to track or signal when a particular condition is true or false.
How does the character ‘A’ compare to the character ‘B’?
a. ‘A’ is greater than ‘B’
b. ‘A’ is less than ‘B’
c. ‘A’ is equal to ‘B’
d. You cannot compare characters
b. ‘A’ is less than ‘B’
Explanation: Characters in Java are compared based on their Unicode values, and ‘A’ has a lower Unicode value than ‘B’.
This is an if statement that appears inside another if statement.
a. nested if statement
b. tiered if statement
c. dislodged if statement
d. structured if statement
a. nested if statement
Explanation: A nested if statement is an if statement that appears inside another if statement.
An else clause always goes with .
a. the closest previous if clause that doesn’t already have its own else clause
b. the closest if clause
c. the if clause that is randomly selected by the compiler
d. none of these
a. the closest previous if clause that doesn’t already have its own else clause
Explanation: The else clause is associated with the closest if that does not already have its own else.
When determining whether a number is inside a range, it’s best to use this operator.
a. &&
b. !
c. ||
d. ? :
a. &&
Explanation: The && (logical AND) operator is used to combine conditions, which is ideal when checking if a number lies within a specific range.
This determines whether two different String objects contain the same string.
a. the == operator
b. the = operator
c. the equals method
d. the stringCompare method
c. the equals method
Explanation: The equals method is used to compare the contents of two String objects for equality.
The conditional operator takes this many operands.
a. one
b. two
c. three
d. four
c. three
Explanation: The conditional (ternary) operator ? : takes three operands: the boolean condition, the value if true, and the value if false.
This section of a switch statement is branched to if none of the case expressions match the switch expression.
a. else
b. default
c. case
d. otherwise
b. default
Explanation: The default section of a switch statement is executed when no case matches the value of the switch expression.
You can use this method to display formatted output in a console window.
a. Format.out.println
b. Console.format
c. System.out.printf
d. System.out.formatted
c. System.out.printf
Explanation: The System.out.printf method is used to display formatted output to the console in Java.