decMe=decMe-0.1;} }
2 、以下程序的输出结果为﹍﹍﹍﹍﹍﹍。
public class Short {
public static void main(String args[]) {
StringBuffer s = new StringBuffer(“Hello”);
if((s.length( )>5)&&( s.append( \ ;
System.out.println(\ } } 3 、以卜程序段的功能为﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍。
import java.io.*;
public class ArrayCount {
public static void main (String[ ] args ) {
int i , n=10 , sum=0 , count=0; int a[ ]=new int[10]; for ( i=O; i BufferedReader br=new BufferedReader ( new InputStreamReader(System.in)); a[i]=Integer.pareInt(br.readLine()); }catch(IOException e){}; for (i=0;i for(i=0;i if(a[i] System.out.println(count); } } 4 、阅读以下程序段: class Parent { void printMe ( ) { System.out.println(“parent”); } } class Child extends Parent { void printMe ( ) { System.out.println(“child”); } void printAll ( ) { super.printMe( ); this.printMe ( ); printMe( ); } } Public class Test_this { public static void main(String args[]) { Child myC=new Child(); myC.printAll(); } } 输出结果为:﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍。 5、已有Bird类的定义如下: Class Bird{ Protected static int referenceCount=0; public Bird(){referenceCount++;} protected void fly(){} static int getReCount() {return referenceCount;} } 有类Nightingale 的定义如下,请写出它的输出结果﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍﹍。 Public class Nightingale extends Bird{ Nightingale(){referenceCount++;} public static void main(String args[]){ System.out.print(“Before:”+referenceCount); Nightingale florence=new Nightingale(); System.out.println(“After:”+referenceCount); florence.fly(); } } 6、以下程序段的输出结果为 class Cruncher { void crunch ( inti ) { System.out.println (\ } Void crunch (String s ) { system.out.println ( \} public static void main (String args[ ]){ Cruncher crun=new Cruncher( ); char ch=’p’ ; crun.crunch(ch); } } 六、编程题(12 分) 设计一个抽象类CompareObject ,里面有抽象方法compareTo用于比较两个对象。然后设计一个类Position 从CompareObject 派生,有x 和y 属性表示其坐标,该类实现compareTo 方法,用于比较两个对象距离原点(0,0 )的距离之差 《JAVA技术》课程作业(一)参考答案 一、单项选择(共25小题,每小题1分) 1-5 BCCAC 6-10 BDBCB 11-15 ABCCB 16C 20 C 18 B 19 B 20 C 21 C 22 B 23 C 24 C 25 C 二、判断题(共15小题,每小题1分) 1× 2∨ 3∨ 4× 5∨ 6× 7∨ 8× 9∨ 10× 11× 12× 13∨1 4∨ 15× 三、填空题(共18个空,每空1分) 1.编写源文件、将源文件编译成字节码文件、运行程序 2. applet、MyApplet.java 3.javac MyJavaApplication.java Java MyJavaApplication 4. 9 5.mouseDrag() 6.单 多 7.destroy() 9.final 10.子、父 11.HTML 四、多项选择题(共6小题,每小题2分) 1.AD 3.AD 4.ABC 五、写出程序功能或运行结果(共6小题,每小题3分) 1. 1.23 2. value is Hello 3. 从键盘读入10个整数存入整型数组a中,然后统计并输出小于元素平均值的元素个数。 4. parent child child 5. Before:0 After:2 6. int version 六、编程题(12 分) abstract class Compareobject { abstract double compareTo(position f); } public class position extends Compareobject { int x,y; position(int x1,int y1) {x=x1; y=y1; } double compareTo(position f) {return Math.sqrt(this.x*this.x+this.y*this.y)- math.sqrt(f.x*f.x+f.y*f.y);} 百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库电大本科JAVA技术试题2008年7月(2)在线全文阅读。
相关推荐: