A-A+

阅读以下说明和Java代码 填补空缺。[说明] java.util库中提供了Vector模板

2022-08-05 22:30:25 问答库 阅读 172 次

问题详情

阅读以下说明和Java代码,填补空缺。
[说明]
java.util库中提供了Vector模板类,可作为动态数组使用,并可容纳任意数据类型。
该类的部分方法说明如下所示:
方法名 含义
add(k) 向vector对象的尾部添加一个元素k
removeElementAt(i) 删除序号为i的元素(vector元素序号从0开始)
isEmpty() 判断vector对象是否含有元素
size() 返回vector对象中所包含的元素个数
[Java代码]
Import ________;
public class JavaMain {
static private final int ________ =6;
public static void main(String[]args) {
Vector theVector=new Vector< _______ >();
//初始化theVector,将theVector的元素设置为0至5
for(int cEachItem=0; cEachItem<ARRAY_SIZE; cEachItem++)
theVector. add(________ );
showVector(theVector); //依次输出theVector巾的元素
theVector. removeElementAt(3);
showVector(theVector);
}
public static void showVector(Vector theVector){
if(theVector. isEmpty()){
System.out.printin("theVector is empty.");
return;
}
for(int loop=0; loop<theVector.size(); loop++) {
System.out.print(theVector.get(loop));
System.out.print(",");
}
System.out.printin();
}
}
该程序运行后的输出结果为:
0, 1, 2, 3, 4, 5
___________请帮忙给出正确答案和分析,谢谢!

参考答案

正确答案:java.util.Vector或java.util.*ARRAY_SIZEIntegercEachItem01245
java.util.Vector或java.util.*ARRAY_SIZEIntegercEachItem0,1,2,4,5 解析:本题考查的是Java语言的基本应用。在使用Java库中的类时,要导入类所在的包,(1)处应为java.util.Vector或java.util.*。(2)处考查的是变量的定义,此处应为ARRAY_SIZE。(3)处是考察Vector模板类存储的数据类型,所以此处应为Integer类型,(4)处代码主要是将循环变量的值存入cEachItern中,因此应为cEachItem。程序开始会输出0,1,2,3,4,5,再次输出时则没有3,应为0,1,2,4,5。

考点:空缺,模板