1、全国自学考试java语言程序设计一试题及答案全国2011年10月自学考试Java语言程序设计(一)试题课程代码:04747一、单项选择题(本大题共10小题,每小题1分,共1O分) 在每小题列出的四个备选项中只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未 选均无分。 1下面供选字符序列中,不属于Java语言关键字的是 ( ) A. throw B. synchronized C. protect D. try 2以下程序代码的输出的结果是 ( ) double x = 25.6; System.out.println(int)x = KeyEvent.VK_A &t= K
2、eyEvent.VK_Z) text.append(char)t+ ); public void keyTyped(KeyEvent e) public void keyReleased(KeyEvent e) 30以下程序的界面有一个文本区text,一个按钮button。程序运行时,单击按钮,则 将文本区中的内容输出到out,其中out为BufferWriter类的一个对象。 public void actionPerformed(ActionEvent e) String s; if(e._= button) try out. _(text.getText(),0,(text.getTex
3、t().length(); out. flush(); text.setText(null); System.exit(0); catch(IOException exp) text.setText(文件定出错! n); System.exit(-1); 31数据库连接方法connectByJdbcOdbc()按给定的数据库URL、用户名和密码连接数 据库,如果连接成功,方法返回连接对象,连接不成功,则返回空。 public static Connection connectByJdbcOdbc(String url, String usemame, String password) Conn
4、ection con = null; try Class. _(sun.jdbc.odbc.JdbcOdbcDriver); catch (Exception e) e.printStackTrace(); return null; try con =_.getConnection(url, usemame, password); catch (SQLException e) e.printStackTrace(); return null; return con; 五、程序分析题(本大题共5小题,每小题4分,共20分) 32阅读下列程序,请写出该程序的输出结果。 class Test32a
5、String name; int age; long number; Test32a(long number, String name,int age) System.out.println(Name: +name); System. out. println(Age: +age); System.out.println(Tel: +number); class Test32b extends Test32a Test32b(long number, String name,int age,boolean b) super(number, name,age); System.out.print
6、ln(Married: +b); public class Test32 public static void main(String args) Test32b abe=new Test32b(4747,Tony,29,true); 33阅读下列程序,请写出该程序的输出结果。 class Test33 String myString = 1; public static void main(String args) Test33 myObj = new Test33(); myObj.stringModifier(myObj.myString); System.out.println( +
7、myObj.myString); void stringModifier(String theString) theString = theString + 2; System.out.print(theString); 34阅读下列程序,请写出该程序的功能。 import java.awt.*; import java.awt.event.*; import java.applet.*; public class Test34 extends Applet implements ActionListener String msg = ; Button bList = new Button3;
8、 public void init() Button yes = new Button(Yes); Button no = new Button(No); Button maybe = new Button(Undecided); bList0 = (Button) add(yes); bList 1 = (Button) add(no); bList2 = (Button) add(maybe); for(inti= 0;i 3; i+) bListi.addActionListener(this); public void actionPerformed(ActionEvent ae) f
9、or(int i = 0;i 3; i+) if(ae.getSource() = bListi) msg = You pressed + bListi.getLabel(); repaint(); public void paint(Graphics g) g.drawString(msg, 6, 100); 35阅读下列程序,请写出该程序的功能。 import java.awt.event.*; import javax.swing.*; import java.awt.*; public class MenuWindow extends JFrame implements ActionL
10、istener JTextField text = new JTextField(); JMenuBar menuBar; JMenu menuFruits; JMenultem menultem1,menultem2,menultem3; public MenuWindow() menuBar = new JMenuBar(); setJMenuBar(menuBar); menuFruits = new JMenu(水果); menuBar.add(menuFruits); menultem 1 = new JMenultem(苹果); menultem1 .addActionListen
11、er(this); menuFruits.add(menultem1 ); menultem2 = new JMenultem(桔子); menultem2.addActionListener(this); menuFruits.add(menultem2); menuFruits.addSeparator(); menultem3 = new JMenultem(退出); menultem3.addActionListener(this); menuFruits.add(menultem3); Container con = getContentPane(); con.add(text);
12、setSize(200,150); setVisible(true); public void actionPerformed(ActionEvent e) if (e.getActionCommand() = 退出) System.exit(0); else text.setText(e.getActionCommand(); public static void main(String args) MenuWindow mw = new MenuWindow(); 36阅读下列程序,请写出该程序的输出结果。 class MyThread extends Thread String mess
13、age; int s; MyThread(String message, int sec) this.message = message; s = sec; public void run( ) try sleep(s); catch(InterruptedException e) System.out.println(message+ +getPriority( ); class ThreadTest public static void main(String args) Thread foo = new MyThread(Foo, 1000); foo.setPriority(Threa
14、d.MIN_PRIORITY); foo.start( ); Thread bar = new MyThread(Bar,800); bar.setPriority(3); bar.start( ); Thread gar = new MyThread(Gar,400); gar.setPriority(7); gar.start( ); Thread kar = new MyThread(Kar, 100); 答:优点:占地小,避免了垃圾污染地下水,产生的热量还可以用来发电。 kar.setPriority(Thread. MAX_PRIORITY); kar.start( ); 10、由于
15、人口迅速增长、环境污染和全球气候变暖,世界人均供水量自1970年以来开始减少,而且持续下降。 19、阳光、空气、水、土壤、岩石、植物、动物构成了我们周围的环境。我们人类也是环境中的一部分,我们都生活在一不定的环境之中。人与自然和谐相处,共同发展,是我们共同的责任。) 注:假设处理机中没有其它线程占用资源。 6、重新使用是指多次或用另一种方法来使用已用过的物品,它也是减少垃圾的重要方法。六、程序设计题(本大题共2小题,每小题6分,共12分) 37.请编写一个方法int findMaximum(intnumbers),要求该方法返回二维数组中元素 的最大值。38小应用程序的paint(Gmphic
16、s g)方法能在屏幕窗口上显示信息和绘图,如果paint()方法能调用repaint()方法,这就能使显示实现动态效果,repaint()方法的功能是先清除paint()方法以前所画的内容,然后再调用paint()方法。 15、经过有效处理的废水,可以排放到湖泊、河流和海洋中,也可以渗入地下。 以下要你编写的paint()方法取随机的坐标位置画一个边长为20个像素的红色正方形。其中随机的坐标位置可以用以下表达式表示: 4、如何借助大熊座找到北极星?(P58) (int)(Mathrandom()*100)+10 另要求paint()方法在绘制正方形后暂停100毫秒。 答:尽可能地不使用一次性用品;延长物品的使用寿命;包装盒纸在垃圾中比例很大,购物时减少对它们的使用。 import javaapplet*;import javaawt*; 2、昆虫种类繁多,分布很广,它们有着和其他动物不同的身体构造和本领。 public class Class 1 extends Applet public void paint(Graphicsg) 8、我们把铁钉一半浸在水里,一半暴露在空气中,过几天我们发现铁钉在空气中的部分已经生锈,在水中的部分没有生锈。通过实验,我们得出铁生锈与空气有关。 请在以下位置编写代码 第二单元 物质的变化
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1