Chapter 3 MC & T/F
A local variable's scope always ends at the closing brace of the block of code in which it is declared.
T
A Boolean expression is one that is either: a) True or false b) x or y c) Positive or negative d) None of the above
A
This is a boolean expression variable that signals when some condition exists in the program: a) Sentinel b) Block c) Flag d) Case
C
In an if/else statement, if the boolean expression is false: a) the first statement or block is executed b) the statement or block following the else is executed c) all statements or blocks are executed d) no statements or blocks are executed
B
These operators use two operands: a) Unary b) Binary c) Tertiary d) None of the above
B
What will be the value of ans after the following code has been executed? int ans = 10; int x = 65; int y = 55; if (x >= y) ans = x + y; a) 10 b) 120 c) 100 d) No value, there is a syntax error
B
If str1 and str2 are both Strings, which of the following will correctly test to determine whether str1 is less than str2? (1) (str < str2) (2) (str1.equals(str2) < 0) (3) (str1.compareTo(str2) < 0) a) 1, 2, and 3 will work b) 2 c) 3 d) 2 and 3
C
What will be printed when the following code is executed? double x = 45678.259; System.out.printf("%, .2f", x); a) 45678.259 b) 0,045,678.26 c) 45,678.26 d) 45,678.3
C
Which of the following expressions will determine whether x is less than or equal to y? a) x > y b) x =< y c) x <= y d) x >= y
C
If chr is a character variable, which of the following if statements is written correctly? a) if (chr = "a") b) if (chr == "a") c) if (chr = 'a') d) if (chr == 'a')
D
What will be the value of ans after the following code has been executed? int x = 90, y = 55, ans = 10; if (x == y); ans *= 2; a) 10 b) 145 c) 20 d) No value, there is a syntax error
D
An important style rule you should follow when writing if statements is to line up (indent) the conditionally executed statement with the if statement.
F
In a switch statement, if two different values for the CaseExpression would result in the same code being executed, you must have two copies of the code, one after each CaseExpression.
F
When two Strings are compared using the compareTo method, the cases of the two strings are not considered.
F
Because the | | operator performs short-circuit evaluation, your boolean expression will generally be evaluated faster if the subexpression that is most likely to be true is on the left.
T