Deck 5: Flow of Control, Part 1: Selection
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/68
Play
Full screen (f)
Deck 5: Flow of Control, Part 1: Selection
1
What is the meaning of the operator !=?
A) Is equal to
B) Is greater than
C) Is not equal to
D) Is assigned to
A) Is equal to
B) Is greater than
C) Is not equal to
D) Is assigned to
C
2
Which of these takes only one boolean expression?
A) NOT operator
B) AND operator
C) OR operator
D) LOGIC operator
A) NOT operator
B) AND operator
C) OR operator
D) LOGIC operator
A
3
Which of the following will be executed with the highest precedence?
A) +
B) &&
C) !
D) >=
A) +
B) &&
C) !
D) >=
C
4
A(n) __________ is writing else clauses that do not match any if conditions.
A) Math class
B) abs method
C) if/else statement
D) dangling else
A) Math class
B) abs method
C) if/else statement
D) dangling else
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
5
To use DeMorgan's Laws, you need to change the AND operator to OR and change the OR operator to AND, and apply the NOT operator (!) to each operand of a logical operator.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
6
The conditional operator (?:) can be used in expressions.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
7
The conditional operator (?:) has lower precedence than the = operator.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
8
The relational operators cannot be used with which of the following?
A) Literal expressions or with object references
B) Boolean expressions or with object references
C) Two operands
D) An expression that evaluates to a primitive numeric type
A) Literal expressions or with object references
B) Boolean expressions or with object references
C) Two operands
D) An expression that evaluates to a primitive numeric type
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
9
Which of the following choices best describes the statements NOT( A AND B ) = ( NOT A ) OR ( NOT B ) and NOT( A OR B ) = ( NOT A ) AND ( NOT B )?
A) Infinite
B) DeMorgan's Laws
C) Morgan DeLorean's Laws
D) None of these is correct.
A) Infinite
B) DeMorgan's Laws
C) Morgan DeLorean's Laws
D) None of these is correct.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following are reasons why some software engineers advocate using curly braces?
A) The curly braces increase clarity.
B) The curly braces highlight the section of code to be executed when the condition is true.
C) Program maintenance is easier.
D) All of these are correct.
A) The curly braces increase clarity.
B) The curly braces highlight the section of code to be executed when the condition is true.
C) Program maintenance is easier.
D) All of these are correct.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
11
What error will a compiler generate if you terminate an if statement with a semicolon?
A) An initiate error
B) An error that it is incorrect to place semicolon here
C) A false block error
D) None of these is correct.
A) An initiate error
B) An error that it is incorrect to place semicolon here
C) A false block error
D) None of these is correct.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
12
The _________ of a variable is the region within a program where the variable can be referenced, or used.
A) scope
B) false block
C) if condition
D) None of these is correct.
A) scope
B) false block
C) if condition
D) None of these is correct.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following will happen if you declare a variable named message after the if statement instead of before it?
A) The scope of message extends from its declaration only until the end of the true block.
B) The scope of message extends from its declaration only until the end of the false block.
C) The scope of message extends from the point where it is declared to the end of the program.
D) The location of the message variable does not affect the output.
A) The scope of message extends from its declaration only until the end of the true block.
B) The scope of message extends from its declaration only until the end of the false block.
C) The scope of message extends from the point where it is declared to the end of the program.
D) The location of the message variable does not affect the output.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
14
An if/else statement is appropriate when the data falls into more than two mutually exclusive categories and the appropriate instructions to execute are different for each category.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
15
What will result if you have an if statement with two else statements?
A) The dangling else will generate a compiler error "if" without "else".
B) The CompareTo will generate a compiler error "else" without "if".
C) The dangling else will generate a compiler error "else" without "if".
D) None of these is correct.
A) The dangling else will generate a compiler error "if" without "else".
B) The CompareTo will generate a compiler error "else" without "if".
C) The dangling else will generate a compiler error "else" without "if".
D) None of these is correct.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
16
Java ignored indents.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
17
Testing an application with if/else statements only once is considered an adequate amount of testing.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
18
A test plan includes running the application with different data values designed to execute true statements in the application.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
19
The threshold when comparing floating point numbers should be the difference that can be tolerated and still consider the numbers equal.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
20
The compareTo method returns:
A) a boolean value.
B) an integer value.
C) either a boolean or an integer value, depending on whether the String object is less than, equal to, or greater than the String argument.
D) an equals value.
A) a boolean value.
B) an integer value.
C) either a boolean or an integer value, depending on whether the String object is less than, equal to, or greater than the String argument.
D) an equals value.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
21
The __________ method returns true if the data in the parameter object matches the data in the object for which the method was called.
A) boolean
B) compareTo
C) equals
D) SimpleDate
A) boolean
B) compareTo
C) equals
D) SimpleDate
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following statements is correct in regards to operator precedence as compared conditional operators?
A) Parentheses operators are lower.
B) Logical OR is lower.
C) Logical AND is lower.
D) Assignment operators are lower.
A) Parentheses operators are lower.
B) Logical OR is lower.
C) Logical AND is lower.
D) Assignment operators are lower.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
23
The Conditional Operate (?:) evaluates a condition and contributes one of two values to the expression based on the value of the condition.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
24
A conditional operator is a statement that evaluates a condition and contributes one of two values to the expression based on the value of the condition.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
25
In the context of a switch statement, the purpose of break statements is to terminate execution of the switch statement.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
26
The execution of statements stops before the end of the switch block is reached when a break statement is encountered.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
27
The variable operation is not necessary for the switch ( operation ) to work.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
28
The following process would work for creating a random roll of a die:
Step 1. Define constant values that will be used to draw the die, position the dots, and display the roll.
Step 2. Set the color to black to draw the dots and use a switch statement on roll to determine which dots to draw.
Step 3. Draw the die itself as red square.
Step 4. Display the roll to verify that you are drawing the correct roll.
Step 1. Define constant values that will be used to draw the die, position the dots, and display the roll.
Step 2. Set the color to black to draw the dots and use a switch statement on roll to determine which dots to draw.
Step 3. Draw the die itself as red square.
Step 4. Display the roll to verify that you are drawing the correct roll.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following expresses the condition "a is less than b and c."
A) a < b || a < c
B) a < b && c
C) a < b && a < c
A) a < b || a < c
B) a < b && c
C) a < b && a < c
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
30
What is the output of the following code?
Int age = 34;
If ( age > 33 )
System.out.print( 1 );
System.out.println( 2 );
A) 0
B) 1
C) 2
D) 12
E) No output
Int age = 34;
If ( age > 33 )
System.out.print( 1 );
System.out.println( 2 );
A) 0
B) 1
C) 2
D) 12
E) No output
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
31
What is the output of the following code?
Int age = 33;
If ( age > 33 )
System.out.print( 1 );
System.out.println( 2 );
A) 0
B) 1
C) 2
D) 12
E) No output
Int age = 33;
If ( age > 33 )
System.out.print( 1 );
System.out.println( 2 );
A) 0
B) 1
C) 2
D) 12
E) No output
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
32
What is the output of the following code?
Int age = 30;
If ( age > 33 )
System.out.print( 1 );
Else
System.out.print( 2 );
System.out.println( 3 );
A) 1
B) 2
C) 12
D) 123
E) 23
Int age = 30;
If ( age > 33 )
System.out.print( 1 );
Else
System.out.print( 2 );
System.out.println( 3 );
A) 1
B) 2
C) 12
D) 123
E) 23
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
33
An else block is mandatory after an if.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
34
When using an if/else if structure, it is mandatory to have an else block.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
35
When using an if/else if structure, we can only use one else if block.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
36
A variable that is declared inside the true (or false) block of an if statement is still in scope after we exit that block.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
37
When comparing two floating-point numbers for equality, it is safe to use the == operator.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
38
When comparing the data in two objects for equality, we typically use the == operator.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
39
"!( a && b ) is equivalent to !a || !b" is one of the two __________ laws.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
40
With the boolean expression a && b, if a is false, the JVM does not evaluate b. This is called __________.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
41
!( a > 3 ) is equivalent to:
A) a < 3.
B) a <= 3.
C) !a < 3.
D) !a <= 3.
E) !( a <= 3 ).
A) a < 3.
B) a <= 3.
C) !a < 3.
D) !a <= 3.
E) !( a <= 3 ).
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
42
!( a > 38 && b <= 67 ) is equivalent to:
A) a <= 38 && !b <= 67.
B) !a > 38 || !b <= 67.
C) !( a > 38 ) && !( b <= 67 ).
D) !( a > 38 ) || !( b <= 67 ).
E) a < 38 || b >= 67.
A) a <= 38 && !b <= 67.
B) !a > 38 || !b <= 67.
C) !( a > 38 ) && !( b <= 67 ).
D) !( a > 38 ) || !( b <= 67 ).
E) a < 38 || b >= 67.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
43
If you have an if/else if/else code sequence with 4 blocks, what is the minimal number of input values that you should use to test your code?
A) 1
B) 2
C) 3
D) 4
E) 5
A) 1
B) 2
C) 3
D) 4
E) 5
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
44
The switch statement can be used instead of an if/else if statement:
A) at any time.
B) only when comparing the value of an expression to a floating point value.
C) only when comparing the value of an expression to any char or integer variable.
D) only when comparing the value of an expression to constant integers, characters, or Strings.
E) only when comparing the value of an expression to a constant String value.
A) at any time.
B) only when comparing the value of an expression to a floating point value.
C) only when comparing the value of an expression to any char or integer variable.
D) only when comparing the value of an expression to constant integers, characters, or Strings.
E) only when comparing the value of an expression to a constant String value.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
45
= is the equality operator.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
46
a && b is true only when both a and b are true.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
47
In an if statement, curly braces around the true block are mandatory.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
48
Inside an if statement, statements inside the true block must be indented, or the code will not compile.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
49
if statements can be nested.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
50
In else if, there is a space between else and if.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
51
a || b is true only when either a or b is true, but not when both a and b are true.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
52
&& and || have the same level of precedence.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
53
Inside the block of a switch statement, the break statements are optional.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
54
You cannot use a switch statement with Strings.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
55
Inside the block of a switch statement, the value of the expression is compared to the __________ constants in order.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
56
Inside the block of a switch statement, the keyword that plays the same role as else in an if or if/else if statement is __________.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
57
Before performing a division, it is a good idea to use an if statement to test if the value of the denominator is __________.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
58
When the data fall into two mutually exclusive categories, the appropriate structure to use is a(n) __________ statement.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
59
Name three String comparison methods.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
60
Convert the following if/else statement to one that uses the conditional operator:
if ( a % 2 == 0 )
System.out.println( "The number is even" );
else
System.out.println( "The number is odd" );
if ( a % 2 == 0 )
System.out.println( "The number is even" );
else
System.out.println( "The number is odd" );
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
61
What structure would you use if the data falls into five mutually exclusive categories, and how many blocks would you have?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
62
Assuming x, y, and z are int variables, evaluate what is wrong with the following expression: x < y && z
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
63
Suppose that a true block is not skipped and curly braces are required. What can you infer about the condition and the number of statements in the true block?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
64
Why would if/else statements simplify processing?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
65
How would you organize nested if statements to specify which else clause pairs with which if statement?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
66
Contrast the equality operator with the Math.abs method to compute a difference between the two numbers and compare the difference to a threshold value.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
67
Explain why you would use equals( String str ).
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
68
In what situation would you use the switch statement instead of an if/else if statement?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck