Chapter12

advertisement
Chapter 12
30 questions
10 fill in the blank
10 true/false
10 multiple choice
Fill in the Blank Questions
1. A(n) __________ method uses a loop to repeat a block of statements.
[iterative]
2. A(n) __________ method is a method that calls itself.
[recursive]
3. A method is __________ recursive if all of its recursive calls occur as the last action performed in the
method.
[tail]
4. The __________ statement causes control to be passed to the end of the switch, so that only one case is
executed within the switch.
[break]
5. A(n) __________ is a Swing component that combines a text field and a drop-down list.
[JComboBox]
6. If no match occurs with the case labels in a switch statement, the __________ case executes.
[default]
7. Many recursive solutions involve breaking a structure into its __________ and tail. The algorithm
recurses on the tail.
[head]
8. A(n) __________ is a geometric shape that has a recursive structure.
[fractal]
9. When a task is simplified by breaking it up into simpler subtasks, it is called method __________.
[decomposition]
10. Each time a method is called, a representation of the method call is placed on the method call
__________.
[stack]
True/False Questions
1.
It is more efficient to call a method five times using recursion that to repeat a for loop five times
TRUE
FALSE
[FALSE]
2. The value of the integral expression of a switch statement must evaluate to a primitive integral value –
byte, short, int char, long, or boolean.
TRUE
FALSE
[TRUE]
3. A tail recursive algorithm is usually easy to convert into an iterative algorithm that does the same
thing.
TRUE
FALSE
[TRUE]
4.
A recursive method uses a loop to repeat an action.
TRUE
FALSE
[FALSE]
5.
Infinite recursion occurs when the recursion is not successfully bounded.
TRUE
FALSE
[TRUE]
6.
The recursive call in tail recursion is the first executed statement.
TRUE
FALSE
[FALSE]
7.
An iterative algorithm is more efficient than a recursive algorithm.
TRUE
FALSE
[TRUE]
8. The switch statement executes all statements following the label that matches a value until a break
statement is encountered.
TRUE
FALSE
[TRUE]
9. The switch statement evaluates its integral expression and then branches to the break statement that
corresponds to the value equal to the expression’s value.
TRUE
FALSE
[FALSE]
10. A case label transfers control out of its enclosing block.
TRUE
FALSE
[FALSE]
Multiple-Choice Questions
1.
What will be printed when printString(“Recursion”) is invoked?
public static void printString(String s) {
if (s.length() == 0)
return;
else {
printString(s.substring(1));
System.out.print(s.charAt(0));
}
} // printString()
A.
B.
C.
D.
[B]
Recursion
noisruceR
ecursion
oisruceR
2.
What will be printed when printString(“Recursion”) is invoked?
public static void printString(String s) {
if (s.length() == 0)
return;
else {
System.out.print(s.charAt(0));
printString(s.substring(1));
}
} // printString()
A.
B.
C.
D.
Recursion
noisruceR
ecursion
oisruceR
[A]
3.
What will be printed when printString(“Recursion”) is invoked?
public static void printString(String s) {
if (s.length() > 0) {
printString(s.substring(1));
System.out.print(s.charAt(0));
}
}
A.
B.
C.
D.
Recursion
noisruceR
ecursion
oisruceR
[B]
4. What type of sort searches for the largest value and swaps it with the last value, then continues to find
the second largest value and swaps it with the next to last value, and so on?
A. sequential
B. iterative
C. recursive
D. selection
[D]
5.
[B]
What type of method calls itself?
A. iterative
B. recursive
C. head
D. tail
6. What type of statement, in conjunction with the break statement, is used for coding multiway selection
structures?
A. iterative
B. recursive
C. switch
D. casel
[C]
7.
What type of component is used to represent a GUI dropdown menu?
A. ItemListener
B. ItemEvent
C. Graphics
D. JComboBox
[D]
8.
Which one of the following is NOT a valid case value in a switch statement?
A. char
B. int
C. float
D. byte
[C]
9.
What type of method places many instances of its local variables on the method call stack?
A. recursive
B. iterative
C. sequental
D. nested
[A]
10. What type of compiler may convert recursive methods into iterative methods so the resulting runtime
program will be more efficient?
A. stack
B. recursive
C. multiway
D. optimizing
[D]
Download