Java面向对象程序设计试题一答案.doc
Java面向对象程序设计试题一答案一、单项选择题:选择第1题:B选择第2题:A选择第3题:C选择第4题:B选择第5题:A选择第6题:A选择第7题:B选择第8题:C选择第9题:B选择第10题:B二、多项选择题多项选择第1题:AB多项选择第2题:BD多项选择第3题:AD多项选择第4题:AD多项选择第5题:BCD多项选择第6题:AB多项选择第7题:ABCD多项选择第8题:ABCD多项选择第9题:BC多项选择第10题:BC三、 填空题答案 填空第1题:x=10,a=3,b=4,c=5填空第2题:java.util填空第3题:(public )(static )(void)(main)(String args)填空第4题:1填空第5题:26 四、 编程题答案1public class HelloWorldpublic static void main(String args)System.out.println("Hello,World!");import java.awt.Graphics;import java.applet.Applet;public class HelloWorld extends AppletString s;public void init()s="Hello World!"public void paint(Graphics g)g.drawString(s,25,25);2class yanghuipublic static void main (String args)int i,j;int yhlevel=10;int yanghui;System.out.println("杨晖三角形:");yanghui=new intyhlevel;for(i=0;i<yanghui.length;i+)yanghuii=new inti+1;yanghui00=1;for (i=1; i<yanghui.length;i+)yanghuii0=1;for(j=1;j<yanghuii.length-1;j+)yanghuiij=yanghuii-1j-1+yanghuii-1j;yanghuiiyanghuii.length-1=1;for (i=0; i<yanghui.length;i+)for(j=0;j<yanghuii.length;j+)System.out.print(yanghuiij+" ");System.out.println(); 输出结果是:杨晖三角形:1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 13import java.io.*;public class MemoControllerFileOutputStream fos;OutputStreamWriter osw;BufferedWriter bw;public MemoController()tryfos=new FileOutputStream("memo.txt",true); osw=new OutputStreamWriter(fos);bw=new BufferedWriter(osw);catch(FileNotFoundException e);public synchronized void append(String s)trybw.write(s,0,s.length(); bw.flush();bw.close();osw.close();fos.close();catch(IOException e)public static void main(String args)MemoController mmc=new MemoController();mmc.append("I am xubin ");4import java.io.*; class Phones static FileOutputStream fos;public static final int lineLength = 81;public static void main(String args) throws IOExceptionbyte phone = new bytelineLength;byte name = new bytelineLength;int I;try fos = new FileOutputStream("phone.numbers");catch(FileNotFoundException e) while (true)System.err.println("Enter a name (enter 'done' to quit)");readLine(name);if ("done".equalsIgnoreCase(new String(name,0,0,4)break; System.err.println("Enter the phone number"); readLine(phone);for (int i=0;phonei!= 0;i+) fos.write(phonei);fos.write(',');for (int i=0;namei!= 0;i+)fos.write(namei); fos.write('n');fos.close(); private static void readLine(byte line) throws IOException int i=0,b=0; while (i<lineLength-1)&&(b=System.in.read()!='n')linei+ = (byte)b; linei=(byte) 0; 5、import java.util.*;import java.text.*; class ThreeTimeThread extends Threadpublic ThreeTimeThread(String str) super(str);public void run() while (true) SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd G 'at' hh:mm:ss z");Date currentTime = new Date();try sleep(1000);catch (Exception e) String dateString = formatter.format(currentTime);System.out.println(getName()+":"+dateString); public static void main(String args) throws Exceptionnew ThreeTimeThread("first").start(); new ThreeTimeThread("second").start();new ThreeTimeThread("third").start();