java第十一章课后习题解答.docx
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
pnladd.add(lblno);
pnladd.add(addno); pnladd.add(lblname); pnladd.add(addname);
pnladd.add(lblscore);
pnladd.add(addscore);
pnladd.add(btnadd); reader.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);ScoreHandler sh = new ScoreHandler();
btnadd.addActionListe ner(sh);
btndelete.addActionListener(sh); btnsearchbyidorname.addActionListener(sh); Container c = getContentPa ne();
JLabel Ibiscore;
JTextField addno;
JTextField addname;
JTextField addscore;
Vector data;
public HashTest() throws HeadlessException { super(”学生成绩管理“);ht=new Hashtable();
1419877542335207
12879493019
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class HashTest extends JFrame {
J Label lblsearchbyidor name;
System.out.print(st.pop(பைடு நூலகம் +n H);
wanghang++;
if(wanghang%5 == 0){
System.out.println(M\nM);
输入13吋的运行结果如下:
C:\j dk5\bin\j ava_Di dea. 1auncher. port=753输出这个系列的前13个数:
第门章常见数据结构及算法分析
【1】设有一数列:a1=3, a2=8,……,an=2an_i+2an.2,使用堆栈结构输出如的若干项。 [解答]:代码如下,运行程序时需要输入一个参数,指出想要输出数列的前多少项#import java.util.Stack;
public class StackShow {
Integer second = new Integer(8);
st.add(first);
st.add(second);
for (int i = 0; i < count-2; i++) {
temp = first.intValue() + second.intValue(); st.add(new Integer(temp));
first = second;
second = new Integer(temp);
}
System.out.println(M输出这个系列的前“+count +”个数:”);
Object result[]=st.toArrayO;
int wanghang = 0;
for (int i = result length-1; i >= 0 ; i—) {
JPanel pnlsearch = new JPanel(); pnlsearch.add(lblsearchbyidorname); pnlsearch.add(txfidorname); pnlsearch.add(btnsearchbyidorname); pnlsearch.add(btndelete);
colnames = new Vector();
colnames.add(H学号”);colnames.add(”姓名”);colnames.add(”成绩”);
data=new Vector();
reader = new JTable(new ReaderTableModel(data,colnames)); reader.setPreferredSize(new Dimension(700,260));
public static void main(String[] args) {
Stack st = new Stack();
int count = Integer.valueOf(args[0]).intValue();
int temp;
Integer first = new Integer(3);
lblsearchbyidomame = new JLabel("学号:H);txfidorname = new JTextField(20); Iblno = new JLabel("学号”);
lblname = new JLabel(H姓名“);lblscore = new JLabel(°分数”);addno = new JTextField(lO); addname = new JTextField(12); addscore = new JTextField(lO); btnsearchbyidorname = new JButton(H查找->n);btnadd = new JButton("新增”);btndelete = new JButton("删除”);
JScrollPane scptable = new JScrollPane(reader,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
J Panel pnladd = new JPanel();
JTextField txfidorname;
JButton btnsearchbyidorname;
JTable reader;
JButton btnadd;
JButton btndelete;
Hashtable ht;
Vector colnames;
JLabel Iblno;
JLabel lblname;
pnladd.add(addno); pnladd.add(lblname); pnladd.add(addname);
pnladd.add(lblscore);
pnladd.add(addscore);
pnladd.add(btnadd); reader.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);ScoreHandler sh = new ScoreHandler();
btnadd.addActionListe ner(sh);
btndelete.addActionListener(sh); btnsearchbyidorname.addActionListener(sh); Container c = getContentPa ne();
JLabel Ibiscore;
JTextField addno;
JTextField addname;
JTextField addscore;
Vector data;
public HashTest() throws HeadlessException { super(”学生成绩管理“);ht=new Hashtable();
1419877542335207
12879493019
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class HashTest extends JFrame {
J Label lblsearchbyidor name;
System.out.print(st.pop(பைடு நூலகம் +n H);
wanghang++;
if(wanghang%5 == 0){
System.out.println(M\nM);
输入13吋的运行结果如下:
C:\j dk5\bin\j ava_Di dea. 1auncher. port=753输出这个系列的前13个数:
第门章常见数据结构及算法分析
【1】设有一数列:a1=3, a2=8,……,an=2an_i+2an.2,使用堆栈结构输出如的若干项。 [解答]:代码如下,运行程序时需要输入一个参数,指出想要输出数列的前多少项#import java.util.Stack;
public class StackShow {
Integer second = new Integer(8);
st.add(first);
st.add(second);
for (int i = 0; i < count-2; i++) {
temp = first.intValue() + second.intValue(); st.add(new Integer(temp));
first = second;
second = new Integer(temp);
}
System.out.println(M输出这个系列的前“+count +”个数:”);
Object result[]=st.toArrayO;
int wanghang = 0;
for (int i = result length-1; i >= 0 ; i—) {
JPanel pnlsearch = new JPanel(); pnlsearch.add(lblsearchbyidorname); pnlsearch.add(txfidorname); pnlsearch.add(btnsearchbyidorname); pnlsearch.add(btndelete);
colnames = new Vector();
colnames.add(H学号”);colnames.add(”姓名”);colnames.add(”成绩”);
data=new Vector();
reader = new JTable(new ReaderTableModel(data,colnames)); reader.setPreferredSize(new Dimension(700,260));
public static void main(String[] args) {
Stack st = new Stack();
int count = Integer.valueOf(args[0]).intValue();
int temp;
Integer first = new Integer(3);
lblsearchbyidomame = new JLabel("学号:H);txfidorname = new JTextField(20); Iblno = new JLabel("学号”);
lblname = new JLabel(H姓名“);lblscore = new JLabel(°分数”);addno = new JTextField(lO); addname = new JTextField(12); addscore = new JTextField(lO); btnsearchbyidorname = new JButton(H查找->n);btnadd = new JButton("新增”);btndelete = new JButton("删除”);
JScrollPane scptable = new JScrollPane(reader,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
J Panel pnladd = new JPanel();
JTextField txfidorname;
JButton btnsearchbyidorname;
JTable reader;
JButton btnadd;
JButton btndelete;
Hashtable ht;
Vector colnames;
JLabel Iblno;
JLabel lblname;