全國(guó)2012年1月自考《Java語(yǔ)言程序設(shè)計(jì)(一)》試題_第8頁(yè)
六、程序設(shè)計(jì)題(本大題共2小題,每小題6分,共12分)
37.編寫(xiě)方法int[] delete(int []a,int d),方法將創(chuàng)建一個(gè)新數(shù)組b,新數(shù)組b中只包含原數(shù)組中所有值不等于d的元素,并返回該新數(shù)組b。
38.以下程序的界面有一個(gè)按鈕ave、一個(gè)文本區(qū)text和一個(gè)標(biāo)簽label。程序運(yùn)行時(shí),在文本區(qū)中輸入數(shù)字序列,單擊ave按鈕,則在標(biāo)簽label中顯示這個(gè)數(shù)字序列中正實(shí)數(shù)的平均值。
注:這里是給定程序的部分代碼,你要編寫(xiě)的是actionPerformed(ActionEvent e)方法。
import javax.swing.*;………
class Ave extends JFrame implements ActionListener{
JLabel label 1,label; JTextArea text; JButton ave;
Ave() {
Container con=getContentPane();
con.setLayout(new GridLayout(2,2));
labell=new JLabel("輸入整數(shù)序列");
text=new JTextArea(5,10);
ave=new JButton("求正實(shí)數(shù)平均值");
label=new JLabel();
con.add(1abel 1);con.add(text);con.add(ave);
ave.addActionListener(this);
con.add(1abel);
………
}
public void actionPerformed(ActionEvent e){
∥請(qǐng)?jiān)谝韵挛恢镁帉?xiě)代碼
首頁(yè) 1 2 3 4 5 6 7 8 尾頁(yè)
責(zé)編: