当前位置: 首页 > 所有资源 > 《面向对象程序设计》资源 > 电大资源网1008《面向对象程序设计》形考任务3答案(课程号:02372)

电大资源网1008《面向对象程序设计》形考任务3答案(课程号:02372)2025年春

最近更新:2020-10-26
832

 

数组的大小自创建以后就固定了。如果需要在序列中存储不同类型的数据,或者需要动态改变其大小,就需要用集合类型,如Vector类。

所有集合类都位于javA.util包下。

集合框架是为表示和操作集合而规定的一种统一的标准体系结构,包含三大块内容:接口、实现和算法。

Set 接口继承 Collection接口,无序不可重复,即Set是无序集合,集合中的元素不可以重复。List 接口也继承 Collection接口,有序可重复,允许重复,即List是有序集合,集合中的元素可以重复。

Map接口是键-值对象,即Map中保存Key-value对形式的元素,访问时只能根据每项元素的key来访问其valuekey不能重复,value可以重复。

数组的长度不能够被改变,而向量类(Vector)对象的长度可以被改变。

向量类Vector中的add(x)方法能够把x元素加入到当前对象的末尾。

向量类Vector中的size()方法能够返回向量中当前保存的元素的个数。

向量类Vector中的get(i)方法不能够返回向量中下标为i的元素值。

向量类Vector中的set(i,x)方法不能够把向量中下标为i的元素值修改为x的值。

下列( )接口不是继承于Collection接口。

下列能表示栈(stacks1长度的是( )

有关Set说法错误的是( )。

有关List说法错误的是(

有关Map说法错误的是( )。

下列哪个类不是异常类的父类?( )。

下面的异常( )不属于非检查型异常。

下面的关键字( )与异常处理无关。

Java语言中,捕获和处理异常的语句块为( )。

下面的异常( )为数组下标越界异常。

"Public class Test {

Public static void main(String[] args) {

Vector teamList = new Vector();

teamList.add(""Z"");

teamList.add(""L"");

teamList.add(""W"");

teamList.remove(0);

teamList.remove(0);

System.out.println(teamList.size()+"",""+teamList.get(0));

}\n      

}

"public class XXK4 {

public static void main(String[] args) {

int [][]a={{2,5,8},{3,6,9},{4,5,6}};

int []b=new int[3];

int i,j;

for(i=0; i<A.length; i++)

for(j=0; j<a.length; j++)

b+=a[j];

for(i=0; i<b.length; i++)

System.out.print(b+"" "");

}

}

"class ABC {

int a,b;

public ABC(int a, int b) {this.a=a; this.b=b;}

public int compareTo(ABC x) {return a*b-x.a*x.b;}

}

public class XXK5 {

public static void main(String[] args) {

int [][]d={{3,8},{4,6},{5,6},{2,9},{6,7},{5,8}};

ABC []ar=new ABC[d.length];

int i,k=0;

for(i=0; i<ar.length; i++)

ar=new ABC(d[0],d[1]);

for(i=1; i<ar.length; i++)

if(ar.compareTo(ar[k])>0) k=i;

System.out.println(""k=""+k);

}

}

"class ABC {

String name;

double price;

public ABC(String na, double pr) {name=na; price=pr;}

public int compareTo(ABC x) {

if(name.compareTo(x.name)>0) return 1;

if(name.compareTo(x.name)<0) return -1;

else return 0;

}

}

public class XXK5 {

public static void main(String[] args) {

String []s={""apple"", ""pear"", ""tangerme"", ""banana"", ""grape""};

double []d={3.8, 2.5, 3.2, 4.3, 5.2};

ABC []ar=new ABC[s.length];

int i,k=0;

for(i=0; i<ar.length; i++)

ar=new ABC(s,d);

for(i=1; i<ar.length; i++)

if(ar.compareTo(ar[k])>0) k=i;

System.out.println(ar[k].name+"" ""+ar[k].price);

}

}

"public class StackTest {

public static void main(String[] args) {

Stack<Integer> st = new Stack<Integer>();

st.push(new Integer(11));

st.push(new Integer(22));

st.push(new Integer(33));

System._out_.println(""size is-> ""+st.size());

System._out_.println(""Top is-> ""+st.peek());

st.pop();

System._out_.println(""new Top is-> ""+st.peek());

}

}

 

下载地址1
3积分
下载附件

重要提示:本站不支持微信或苹果手机充值及下载,为了避免下载出错,请用电脑访问下载资源