设为首页    加入收藏

自学考试省级导航

全国 A安徽 B北京 C重庆 F福建 G广东 广西 甘肃 贵州 H河南 河北 湖南 湖北 黑龙江 海南 J江苏 江西 吉林 L辽宁 N内蒙古 宁夏 Q青海 S山东 山西 陕西 四川 上海 T天津
     X新疆 西藏 Y云南 Z浙江 历年真题分类检索

全国2012年1月自学考试《Java语言程序设计(一)》真题(word下载版)(五)
2015-02-09 20:08:26 来源:91考试网 作者:www.91exam.org 【

五、程序分析题(本大题共5小题,每小题4分,共20分)
32.阅读下列程序,请写出该程序的功能。
public  class  Test32
{   public  static  void   main(String   args[])
{   double   sum=0.0;
For   (int i=1;  i<=500;i++)
sum+=1.0/(double)i;
System.out.println( "sum="+sum);
}
}
33.阅读下列程序,请回答以下问题:
(1)界面中有哪些组件?
(2)点击每一个按钮分别会显示什么内容?
import java.applet.*;  import java.awt.*;
import java.awt,event.*;import javax.swing.*;
public class Test33 extends Applet implements ActionListener{
String msg="";
String buttonCom[]={"Yes","No","Undecided"};
JButton bList[]=new JButton[buttonCom.length];
JTeXtField t;
public void init(){
setLayout(new GridLayout(4,1));
for(int i=0;i<buttonCom.1ength;i++){
bList[i]=new JButton("按钮"+(i+1));
add(bList[i]);
bList[i].addActionListener(this);
}
t=new JTeXtField();
add(t);
}
public void actionPerformed(ActionEvent e){
for(int i=0;i<3;i++){
if(e.getSource()一bList[i]){
t.setTeXt("You pressed"+buttonCom[i]);
break;
}
}
}
}
34.阅读下列程序,请写出该程序的功能。
import java.io.*;  import java.awt.*;  import javax.swing.*;
import java.awt.event.*;
class MyWindow extends JFrame implements ActionListener{
JTextArea text;BufieredReader in;JTextField fileName;
FileReader file;
MyWindow(){
Contaiher con=this.getContentPane();//获得内容面板
con.setLayout(new BorderLayout());
fileName=new JTextField("输入文件名");
fileName.addActionListener(this);
text=new JTextArea(20,30);
JScrollPane jsp:new JScrollPane(text);
con.add(jsp,BorderLayout.CENTER);
con.add(fileName,"South");setVisible(true);
}
public void actionPerformed(ActionEvent e)
{    String s;
try{File f=new File(fileName.getText());
file=new FileReader(f);
in=new BufferedReader(file);
} catch(FileNotFoundException el){}
try{ while((s=in.readLine())!=null)
text.append(s+’\n’);
}catch(IOException exp){}
}
}
public class Test34{
public static void main(String args[ ])   {new MyWindow();}
}
Tags:自学考试 历年真题
】【打印繁体】 【关闭】 【返回顶部
上一篇浙江省2012年10月高等教育自学考.. 下一篇全国2013年1月高等教育自学考试Ja..

网站客服QQ: 960335752 - 14613519 - 48225117