Chapter 12
2 True/False
1. The expression s.charAt(0) will generate an exception if the string is the empty string.
[TRUE]
2. Recursive algorithms are easier to design than their corresponding iterative algorithms.
[TRUE]
5 Fill in the blank
1. A recursive definition consists of two parts: a recursive part in which the nth value is defined in terms of the (n – 1)st value, and a(n) __________ case which defines a boundary condition.
[nonrecursive]
2. The following formula is used to calculate the __________ of n: n! = n * (n – 1) * (n – 2) * … 1, for n > 0
[factorial]
3. A(n) __________ repetition will occur if a recursive definition is not properly bounded.
[infinite]
4. A recursive __________ controls the progress of the recursion toward its bound.
[parameter]
5. A(n) __________ compiler can convert a recursive method into an iterative mentod when the program is compiled.
[optimizing]
5 Multiple Choice
1. What method is called automatically whenever the an applet repaints itself?
A. paint()
B. paintComponent()
C. repaint()
D. paintApplet()
[B]
2. What method will retrieve the position selected within a menu of a JComboBox?
A. getSelectedIndex()
B. getSelectedItem()
C. getIndex()
D. getItem()
[B]
3. Method call and return in Java, and all other programming languages, uses a
__________ protocol.
A. first-in-first-out
B. first-in-last-out
C. last-in-first-out
D. last-in-last-out
[C]
4. A string and a(n) __________ can be divided into its head, the first element, and its tail, the rest of its elements.
A. array
B. component
C. parameter
D. character
[A]
5. As each method is called, a representation of the method call is place d on the method call __________.
A. parameter
B. base
C. stack
D. taill
[C]