网友您好, 请在下方输入框内输入要搜索的题目:

题目内容 (请给出正确答案)

阅读以下说明和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代码,填补空缺。[说明]java.util库中提供了Vector模板类,可作为动态数组使用,并可容纳任意数据类型。该类的部分方法说明如下所示:方法名 含义add(k) 向vector对象的尾部添加一个元素kremoveElementAt(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至5for(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___________ ” 相关考题
考题 下列关于Arrays类说法错误的是() A、Arrays类用于对数组进行排序和搜索的类B、Arrays类提供了sort()和binarySearch()的方法C、Arrays类是自定义的可以实现排序和查找的操作类D、Arrays类定义在java.util包中

考题 阅读以下说明和Java代码,将应填入(n)处的字句写在对应栏内。【说明】java.util库中提供了Vector模板类,可作为动态数组使用,并可容纳任意数据类型。该类的部分方法说明如下表所示:【Java代码】import (1);public class JavaMain {static private final int (2)= 6;public static void main(String[] args){Vector<Integer> theVector = new Vector< (3) >();// 初始化 theVector, 将theVector的元素设置为0至5for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++)theVector.add((4));showVector(theVector); // 依次输出theVector中的元素theVector.removeElementAt(3);showVector(theVector);}public static void showVector(Vector<Integer> theVectorif (theVector.isEmpty()) {System.out.println("theVectcr is empty.");return;}for (int loop = 0; loop < theVector.size(); loop++)System.out.print(theVector.get(loop));System.out.print(", ");}System.out.println();}}该程序运行后的输出结果为:0,1,2,3,4,5(5)

考题 阅读以下说明和C++代码,将应填入(n)处的字句写在对应栏内。【说明】C++标准模板库中提供了vector模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为std。vector模板类的部分方法说明如下表所示:【C++代码】include <iostream>include <vector>using namespace (1);typedef vector< (2) > INTVECTOR;const int ARRAY_SIZE = 6;void ShowVector (INTVECTOR theVector);int main() {INTVECTOR theVector;// 初始化 theVector, 将theVector的元素依次设置为0至5for (int cEachItem = 0; cEachItem < ARRAY_SIZE; cEachItem++}theVector.push_back((3));ShowVector(theVector); // 依次输出theVector中的元素theVector.erase (theVector.begin () + 3};ShowVector(theVector);}void ShowVector (INTVECTOR theVector) {if (theVector.empty ()) {cout << "theVector is empty." << endl; return;}INTVECTOR::iterator (4);for (theIterator=theVector.begin(); theIterator !=theVector.end(); theIterator++) {cout << *theIterator;if (theIterator != theVector.end()-1) cout << ", ";}cout << end1;}该程序运行后的输出结果为:0,1,2,3,4,5(5)

考题 阅读以下说明和JAVA 2代码,将应填入(n)处的字句写在对应栏内。[说明]以下程序为类类型的变量应用实例,通过异常处理检验了类CCircle的变量的合法性,即参数半径应为非负值。仔细阅读代码和相关注释,将程序补充完整。[JAVA代码]//定义自己的异常类class CCircleException extends Exception{}// 定义类 CCircleclass CCircle{private double radius;public void setRadius ( double r ) (1){if ( r<0 ) {(2)}else(3)}Public void show ( ) {System. out. println ( "area="+3.14*radius*radius );}}public class ciusample{public static void main ( String args[] ){CCircle cir=new CCircle( );(4) {cir. setRadius ( -2.0 )}(5){System. out. println ( e+" throwed" ) ;}cir. show( ) ;}}

考题 阅读以下说明和Java程序,填补代码中的空缺(1)~(6),将解答填入答题纸的对应栏内。【说明】很多依托扑克牌进行的游戏都要先洗牌。下面的Java代码运行时先生成一副扑克牌,洗牌后再按顺序打印每张牌的点数和花色。【Java代码】

考题 试题六(共 15 分)阅读以下说明和 C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]C++标准模板库中提供了 vector 模板类,可作为动态数组使用,并可容纳任意数据类型,其所属的命名空间为 std。vector模板类的部分方法说明如下表所示:[C++代码]include iostreaminclude vectorusing namespace (1) ;typedef vector (2) INTVECTOR;const int ARRAY_SIZE = 6;void ShowVector(INTVECTOR theVector);int main(){INTVECTOR theVector;// 初始化 theVector,将 theVector的元素依次设置为 0 至 5for (int cEachItem = 0; cEachItem ARRAY_SIZE; cEachItem++)theVector.push_back( (3) );ShowVector(theVector); // 依次输出 theVector中的元素theVector.erase(theVector.begin() + 3);ShowVector(theVector);}void ShowVector(INTVECTOR theVector) {if (theVector.empty()) {cout "theVector is empty." endl; return;}INTVECTOR::iterator (4) ;for (theIterator = theVector.begin(); theIterator != theVector.end(); theIterator++){cout *theIterator;if (theIterator != theVector.end()-1) cout ", ";}cout endl;}该程序运行后的输出结果为:0, 1, 2, 3, 4, 5(5)

考题 试题七(共 15 分)阅读以下说明和 Java 代码,将应填入 (n) 处的字句写在答题纸的对应栏内。[说明]java.util 库中提供了 Vector 模板类,可作为动态数组使用,并可容纳任意数据类型。该类的部分方法说明如下表所示:[Java 代码]import (1) ;public class JavaMain {static private final int (2) = 6;public static void main(String[] args){VectorInteger theVector = new Vector (3) ();// 初始化 theVector,将 theVector的元素设置为 0 至 5for (int cEachItem = 0; cEachItem ARRAY_SIZE; cEachItem++)theVector.add( (4) );showVector(theVector); // 依次输出 theVector中的元素theVector.removeElementAt(3);showVector(theVector);}public static void showVector(VectorInteger theVector){if (theVector.isEmpty()) {System.out.println("theVector is empty.");return;}for (int loop = 0; loop theVector.size(); loop++) {System.out.print(theVector.get(loop));System.out.print(", ");}System.out.println();}}该程序运行后的输出结果为:0, 1, 2, 3, 4, 5(5)

考题 java.util包中提供了一个专门用于操作数组的工具类,这个类是()。

考题 java.util包中提供了一个专门用来操作集合的工具类,这个类是()