Java Reference
In-Depth Information
12. A merge sort of 32 elements will generate 63 total calls to mergeSort and will
perform the merge operation 31 times.
13. (a)
{1, 2, 3, 4, 5, 11, 9, 7, 8, 10}
(b)
{7, 2, 8, 4, 1, 11, 9, 5, 3, 10}
{7, 2, 8, 4, 1}, {11, 9, 5, 3, 10}
{7, 2}, {8, 4, 1}, {11, 9}, {5, 3, 10}
{7, 2}, {8, 4, 1}, {11, 9}, {5, 3, 10}
{7}, {2}, {8}, {4, 1}, {11}, {9}, {5}, {3, 10}
{4}, {1}, {3}, {10}
{2, 7}, {8}, {1, 4}, {9, 11}, {5}, {3, 10}
{2, 7}, {1, 4, 8}, {9, 11}, {3, 5, 10}
{1, 2, 4, 7, 8}, {3, 5, 9, 10, 11}
{1, 2, 3, 4, 5, 7, 8, 9, 10, 11}
14. (a)
{-3, 1, 1, 2, 4, 8, 7, 21, 12, 30, 6, 9}
(b)
{7, 1, 6, 12, -3, 8, 4, 21, 2, 30, -1, 9}
{7, 1, 6, 12, -3, 8}, {4, 21, 2, 30, -1, 9}
{7, 1, 6}, {12, -3, 8}, {4, 21, 2}, {30, -1, 9}
{7}, {1, 6}, {12}, {-3, 8}, {4}, {21, 2}, {30}, {-1, 9}
{7}, {1, 6}, {12}, {-3, 8}, {4}, {21, 2}, {30}, {-1, 9}
{1}, {6}, {-3}, {8}, {21}, {2}, {-1}, {9}
{7}, {1, 6}, {12}, {-3, 8}, {4}, {2, 21}, {30}, {-1, 9}
{1, 6, 7}, {-3, 8, 12}, {2, 4, 21}, {-1, 9, 30}
{-3, 1, 6, 7, 8, 12}, {-1, 2, 4, 9, 21, 30}
{-3, -1, 1, 2, 4, 6, 7, 8, 9, 12, 21, 30}
Chapter 14
1. The packages are java.awt , java.awt.event , and javax.swing . The state-
ments to import these packages are as follows:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
2. String response = JOptionPane.showInputDialog(null,
"What's your age, cowboy?");
int age = Integer.parseInt(response);
if (age < 40) {
JOptionPane.showMessageDialog(null, "Only " + age +
"... still a young'n.");
} else {
JOptionPane.showMessageDialog(null, "You're " +
age + "... howdy, old timer!");
}
 
Search WWH ::




Custom Search