int index = 1;  int [] foo = new int [3];  int bar = foo [index];  int baz = bar + index;   What is the result?()  A、 Baz has the value of 0B、 Baz has the value of 1C、 Baz has the value of 2D、 An exception is thrown.E、 The code will not compile.

题目

int index = 1;  int [] foo = new int [3];  int bar = foo [index];  int baz = bar + index;   What is the result?()  

  • A、 Baz has the value of 0
  • B、 Baz has the value of 1
  • C、 Baz has the value of 2
  • D、 An exception is thrown.
  • E、 The code will not compile.

相似考题

2.试题二(共15分)阅读下列说明,回答问题1至问题3,将解答填入答题纸的对应栏内。【说明】逻辑覆盖法是设计白盒测试用例的主要方法之一,它是通过对程序逻辑结构的遍历实现程序的覆盖。针对以下由C语言编写的程序,按要求回答问题。struct _ProtobufCIntRange{int start_value;unsigned orig_index;};typedef struct _ProtobufCIntRange ProtobufCIntRange;int int_range_lookup (unsigned n_ranges, const ProtobufCIntRange *ranges, int value){unsigned start,n; ∥1start=0;n=n_ranges;while(n>1){ //2unsigned mid= start+ n/2;if(value< ranges[mid].start_value){ //3n=mid-start; //4}else if(value>=ranges[mid].start value+(int)(ranges[mid+1].orig_index-ranges[mid].orig_index){ //5unsigned new_start= mid+1; //6n=start+n-new_start,start = new_start;}else //7return (value - ranges[mid].start_value)+ ranges[mid],orig_index;}if(n>0){ //8unsigned start_orig_index= ranges[start].orig_index;unsigned range_size=ranges[start+1].orig_index - start_orig_index;if (ranges[start].start_value<=value&& value< (int)(ranges[start].start_value+ range_size》 //9, 10return (value - ranges[start].start_value)+start_orig_index; //11}retum -1, //12} //13【问题1】(5分)请给出满足100%DC(判定覆盖)所需的逻辑条件。【问题2】 (7分)请画出上述程序的控制流图,并计算其控制流图的环路复杂度V(G)。【问题3】(3分)请给出【问题2】中控制流图的线性无关路径。

更多“int index = 1;&e”相关问题
  • 第1题:

    请写出如下程序的输出结果:

    #include

    int a[]={2,4,6,8,10};

    int &index(int i)

    { return a[i];

    }

    void main()

    {

    int i;

    index(3)=12;

    for (i=0;i<=4;i++)

    cout<


    答案:2 4 6 12 10

    解析:

    int &index(int i) 函数返回的是 a[i] 的引用,在main函数中修改了a[3]=12,故最终数组a的结果如答案所示。

  • 第2题:

    intindex=1;int[]foo=newint[3];intbar=foo[index];intbaz=bar+index;Whatistheresult?()

    A.Bazhasthevalueof0

    B.Bazhasthevalueof1

    C.Bazhasthevalueof2

    D.Anexceptionisthrown.

    E.Thecodewillnotcompile.


    参考答案:B

  • 第3题:

    下面程序执行后,baz的值应是______。 public class Test9 { public static void main(String[] args) { int index = 1; int fox[] = new int [3]; iht bar = fox [index]; int baz = bar + index; System.out.println(baz); } }

    A.0

    B.1

    C.2

    D.编译错误


    正确答案:B
    解析:int fox[]=new int[3]这时数组的每个元素都初始化为0,所以int baz=bar+index;,其实,这时bar的值为0,这样便有baz的值为1。

  • 第4题:

    关于以下初始化序列的执行结果的说法正确的是( )。 int index=1; int[] foo=new int[3]; int bar=foo[index]; int baz=bar+index;

    A.baz的值为0

    B.baz的值为1

    C.编译通过,但产生异常

    D.编译不能通过


    正确答案:B

  • 第5题:

    试题五(共 15 分)

    阅读下列说明、图和C++代码,将应填入 (n) 处的字句写在答题纸的对应栏内。

    [说明]

    已知对某载客车辆(Car)进行类建模,如图 5-1所示,其中类 Engine 表示发动机引擎,类 Wheel 表示车轮,类 Body 表示车身,类 Driver 表示司机,类 Passenger 表示乘客。

    [C++代码]

    const int (1) = 7; //定义最多载客数

    const int MAX_WHEELS = 5; //定义最多轮胎数

    class Body{ //此处代码省略 }; //车身类

    class Passenger{ //此处代码省略 }; //乘客类

    class Wheel{ //此处代码省略 }; //车轮类

    class Driver{ //司机类

    public:

    string name; //表示第几路公交车司机

    Driver(string driverName):name( (2) ){}; //构造函数

    };

    class Engine{ //引擎类

    public:

    string engineNo; //引擎编号

    Engine(string engineNo){ (3) ->engineNo = engineNo; } //构造函数

    };

    class Car{ //汽车类

    protected:

    Engine * engine; Driver * driver; Body body;

    Wheel * wheels[MAX_WHEELS]; Passenger * passengers[MAX_PASSENGERS];

    public:

    Car(Driver *driver){ //构造函数

    this->driver = driver;

    engine = new Engine("TX6536 型号引擎");

    for (int index = 0; index < MAX_WHEELS; index++){

    wheels[index] = new Wheel();

    }

    for (int index = 0; index < MAX_PASSENGERS; index++){

    passengers[index] = NULL;

    }

    }

    virtual ~Car(){ //析构函数

    for (int index=0; index < MAX_WHEELS; index++)

    delete wheels[index];

    delete (4) ;

    }

    int getPassengerNumber(){ //获取车上乘客数量

    //此处代码省略

    }

    void getOnPassenger(Passenger * aPassenger ){ //乘客上车

    //此处代码省略

    }

    void run(){ //开车

    if(driver == NULL){ cout << "司机尚未上车!"; return; }

    //此处代码省略

    }

    };

    void main(){

    Driver driver("第五路公交车司机");

    Car car( (5) );

    Passenger passengers[MAX_PASSENGERS];

    for (int index = 0 ; index < MAX_PASSENGERS; index ++) //乘客上车处理

    car.getOnPassenger(&passengers[index]);

    car.run();

    }


    正确答案:


  • 第6题:

    Table TAB1 was created using the following statement: CREATE TABLE tab1 (c1 INT, c2 INT, c3 INT, c4 INT, c5 INT); If column C1 is unique and queries typically access columns C1 and C2 together, which statement(s) will create index(es) that will provide optimal query performance? ()

    • A、 CREATE UNIQUE INDEX xtab1 ON tab1 (c1) include (c2)
    • B、 CREATE UNIQUE INDEX xtab1 ON tab1 (c1);  CREATE INDEX xtab2 ON tab1 (c3) INCLUDE (c2) 
    • C、 CREATE UNIQUE INDEX xtab1 ON tab1 (c2, c1)
    • D、 CREATE UNIQUE INDEX xtab1 ON tab1 (c2) INCLUDE (c1)

    正确答案:A

  • 第7题:

    charAt(int index)表示从字符串中取得一个字符,该字符的位置是index


    正确答案:正确

  • 第8题:

    int index = 1;   int foo = new int ;   int bar = foo [index];   int baz = bar + index;   What is the result?()

    • A、 Baz has the value of 0
    • B、 Baz has the value of 1
    • C、 Baz has the value of 2
    • D、 An exception is thrown.
    • E、 The code will not compile.

    正确答案:B

  • 第9题:

    单选题
    下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(  )。public class FindKeyWords{ public static void main(String[]args) {  String text = An array is a data structur that stores a collection of   +values of the same type. You access each individual value   +through an integer index. For example,if a is an array   +of inergers,then a[i] is the ith integer in the array.;  int arrayCount=0;  int index=-1;  String arrayStr=array;  index=text.indexOf(arrayCount);  while(index ______ 0)  {   ++arrayCount;   index+=arrayStr.length();   index=text.indexOf(arrayStr,index);   System.out.println(the text contains+arrayCount+arrays);  } }}
    A

    <

    B

    =

    C

    <=

    D

    >=


    正确答案: C
    解析:
    indexOf()方法有以下四种形式:
    ①public int indexOf(int ch):返回指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回-1。
    ②public int indexOf(int ch, int fromIndex):返回从 fromIndex 位置开始查找指定字符在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回-1。
    ③int indexOf(String str):返回指定字符串在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回 -1。
    ④int indexOf(String str, int fromIndex):返回从fromIndex位置开始查找指定字符串在字符串中第一次出现处的索引,如果此字符串中没有这样的字符,则返回-1。
    在while循环中,每次indexOf()方法都从上次报告索引再加上该指定字符长度(即跳过上次找到的字符)的位置开始查找。若还能找到,则返回一个大于等于0的整数,为匹配的字符的索引;否则,返回-1。所以程序中只有当indexOf()方法返回的index>=0时,才继续执行while循环。

  • 第10题:

    单选题
    int index = 1;  int [] foo = new int [3];  int bar = foo [index];  int baz = bar + index;   What is the result?()
    A

     Baz has the value of 0

    B

     Baz has the value of 1

    C

     Baz has the value of 2

    D

     An exception is thrown.

    E

     The code will not compile.


    正确答案: C
    解析: 暂无解析

  • 第11题:

    单选题
    Table TAB1 was created using the following statement: CREATE TABLE tab1 (c1 INT, c2 INT, c3 INT, c4 INT, c5 INT); If column C1 is unique and queries typically access columns C1, C2 and C3 together, which statement(s) will createindex(es) that will provide optimal query performance?()
    A

    CREATE UNIQUE INDEX xtab1 ON tab1 (c1); CREATE INDEX xtab2 ON tab1 (c2) INCLUDE (c3)  

    B

    CREATE UNIQUE INDEX xtab1 ON tab1 (c1) INCLUDE (c2, c3) 

    C

    CREATE UNIQUE INDEX xtab1 ON tab1 (c3, c2, c1)  

    D

    CREATE UNIQUE INDEX xtab1 ON tab1 (c2) INCLUDE (c1, c3)


    正确答案: B
    解析: 暂无解析

  • 第12题:

    单选题
    int index = 1;   String test = new String;   String foo = test[index];  What is the result?()
    A

      Foo has the value “”

    B

     Foo has the value null

    C

     An exception is thrown

    D

     The code will not compile


    正确答案: A
    解析: 暂无解析

  • 第13题:

    下面函数的作用是【 】。

    int index(int x,int a[],int n)

    {

    for(int i=0;i<n;i++)

    {

    if(a[i]==x)

    return i;

    }

    return i;

    }


    正确答案:数组a中查找x若有则返回第一个x的下标若没有则返回n
    数组a中查找x,若有则返回第一个x的下标,若没有则返回n 解析:函数的作用是通过变量数组,在数组中查找x,若找到则显示下标i。

  • 第14题:

    请完成Java程序:本题是一个冒泡排序程序的实例。冒泡排序的含义是将相邻的两个数作比较,如果是升序排列的话,如果前边的数大,则将两个数交换。从第一个数开始两两比较一次,就可以将最大的数移动到最后。

    注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。

    import java.io.*;

    public class simple

    {

    public static int[]Data=new int[10];

    public static void main(String[] args)

    int i;

    int Index;

    Index=0;

    InputStreamReader ir;

    BufferedReader in;

    ir=new InputStreamReader(System.in);

    in=new BufferedReader(ir);

    try

    {

    do

    {

    System.out.println("Please input the number"+

    Index+"you want to sort(Exit for 0):");

    String s=in.readLine();

    Data[Index]=Integer.parseInt(s);

    Index++;

    }

    while(Data[Index-1]!=0);

    }

    catch(IOException e)

    {

    System.out.println(e.getMessage());

    }

    System.out.print("Before bubble sorting:");

    for(i=0; i<Index-1; i++)

    System.out.print(" "+Data[i]+" ");

    System.out.println(" ");

    BubbleSort(Index-1);

    System.out.print("After Bubble Sorting:");

    for(i=0; i<Index-1;i++)

    System.out.print(" "+Data[i]+" ");

    System.out.println(" ");

    }

    public static void BubbleSort(int Index)

    {

    int i, j, k;

    boolean Change;

    int Temp;

    for(j=Index; j>1;j--)

    {

    Change=false;

    for(i=0; i<j-1;i++)

    {

    if(Data[i+1]<Data[i])

    {

    Temp=Data[i+1];

    Data[i+1]=Data[i];

    ______;

    ______;

    }

    }

    if(Change)

    {

    System.out.print("Current Sorting Result:");

    for(k=0; k<Index; k++)

    System.out.print(" "+Data[k]+" ");

    System.out.println(" ");

    }

    }

    }

    }


    正确答案:Data[i]=Temp Change=true
    Data[i]=Temp Change=true 解析:本题考查知识点:基本排序算法。冒泡排序是最常用的交换排序方式,其核心算法就是比较和交换。交换的最简单方法是用一个中间变量作交换中介。先把其中一个值存入临时变量,然后将另一个值赋给第一个值,最后将临时变量赋给另一个值(第1个空)。另外,为加快速度,如果排序已经完成了,就可以直接返回,而不必等待循环结束(第2个空,将标志变量设为真)。

  • 第15题:

    阅读下列说明、图和C++代码,填补空缺。

    [说明]

    已知对某载客车辆(Car)进行类建模,如图12-2所示,其中类Engine表示发动机引擎,类Wheel表示车轮,类Body表示车身,类Driver表示司机,类Passenger表示乘客。

    const int __________ =7; //定义最多载客数

    const int MAX_WHEELS=5; //定义最多轮胎数

    class Body{ //此处代码省略 ); //车身类

    class Passenger{ //此处代码省略}; //乘客类

    Class Wheel{ //此处代码省略}; //车轮类

    Class Driver{ //司机类

    public:

    string name; //表示第几路公交车司机

    Driver(string driverName):marne( __________ ){}; //构造函数

    };

    class Engine{ //引擎类

    public:

    string engineNo; //引擎编号

    Engine(string engineNo){ __________ ->engineNo=engineNo; }

    //构造函数

    };

    Class Car{ //汽车类

    protected:

    Engine *engine; Driver *driver; Body body;

    Wheel *wheels[MAX_WHEELS]; Passenger *passengers[MAX_PASSENGERS];

    public:

    Car(Driver *driver)( //构造函数

    this->driver=driver;

    engine=new Engine("TX653 6型号引擎");

    for(int index=0; index<MAX_WHEELS; index++){

    wheels[index]=new Wheel( );

    }

    for(int index=0; index passengers[index]=NULL;

    }

    }

    virtual -Car( ){ //析构函数

    for (int index=0; index<MAX_WHEELS; index++)

    delete wheels[index];

    delete __________ ;

    }

    int getPassengerNumber( ){ //获取车上乘客数量

    //此处代码省略

    }

    void getonpassenger(Passenger *apassenger ){

    //乘客上车

    //此处代码省略

    }

    void run( ){ //开车

    if(driver==NULL){cout<< "司机尚未上车!"; return; }

    //此处代码省略

    }

    };

    void main( ){

    Driver driver("第五路公交车司机");

    Car car( __________ );

    Passenger passengers[MAX_PASSENGERS];

    for(int index=0; index<MAX_PASSENGERS; index++)

    //乘客上车处理

    car. getOnPasSenger(&passengers[index]);

    car. run( );

    }


    正确答案:MAX_PASSENGERS driverName this engine &driver
    MAX_PASSENGERS driverName this engine &driver 解析:根据类图描述,分析可得:一辆汽车可以载0~7名乘客,一辆汽车可以被一个或者多个司机驾驶,并且一辆汽车有4~5个轮胎,一个引擎和一个车框架。程序代码中空(1)处表示一辆汽车最多载客数目,从后面的程序代码分析可得,应该填写MAX_PASSENGERS。空(2)处用于构造一个司机对象,需要司机名称driverName作为参数。空(3)处主要设置车的假设司机,由于参数的名称与成员变量的名称相同,因此需要加上this以示区别。空(4)处所对应代码段是汽车car的析构函数,与car的构造函数相对应,需要将构造函数中创建的引擎和车轮删除,所以空(4)处应为删除引擎。空(5)处用于产生一个汽车对象,所以,需要给汽车对象传递合适的参数,构造方法中需要传递一个司机对象,因此应该将driver对象传递到汽车对象中。

  • 第16题:

    下列程序执行后,baz的值应是 int index=1; int fox[ ]=new int[3]; Int bar=fox[index]; int baz:bar+index;

    A.0

    B.1

    C.2

    D.编译错误


    正确答案:B
    解析:intfox[]=newint[3];这时数组的每个元素都初始化为0,所以intbaz=bar+index;其实,这时bar的值是0,这样便有baz的值1。

  • 第17题:

    int index = 1;   String test = new String;   String foo = test[index];  What is the result?()

    • A、  Foo has the value “”
    • B、 Foo has the value null
    • C、 An exception is thrown
    • D、 The code will not compile

    正确答案:B

  • 第18题:

    StringBuffer deleteCharAt(int index)表示删除索引index-1处的字符


    正确答案:错误

  • 第19题:

    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()

    • A、 Foo has the value of 0.
    • B、 Foo has the value of null.
    • C、 Foo has the value of true.
    • D、 Foo has the value of false.
    • E、 An exception is thrown.
    • F、 The code will not compile.

    正确答案:D

  • 第20题:

    int index = 1;  String [] test = new String[3];  String foo = test[index];     What is the result?()  

    • A、 Foo has the value “”
    • B、 Foo has the value null
    • C、 An exception is thrown
    • D、 The code will not compile

    正确答案:B

  • 第21题:

    单选题
    int index = 1;   int foo = new int ;   int bar = foo [index];   int baz = bar + index;   What is the result?()
    A

     Baz has the value of 0

    B

     Baz has the value of 1

    C

     Baz has the value of 2

    D

     An exception is thrown.

    E

     The code will not compile.


    正确答案: A
    解析: 暂无解析

  • 第22题:

    单选题
    int index = 1;   boolean test = new Boolean;   boolean foo= test [index];  What is the result?()
    A

     Foo has the value of 0.

    B

     Foo has the value of null.

    C

     Foo has the value of true.

    D

     Foo has the value of false.

    E

     An exception is thrown.

    F

     The code will not compile.


    正确答案: F
    解析: 暂无解析

  • 第23题:

    判断题
    StringBuffer deleteCharAt(int index)表示删除索引index-1处的字符
    A

    B


    正确答案:
    解析: 暂无解析

  • 第24题:

    单选题
    int index = 1;  String [] test = new String[3];  String foo = test[index];     What is the result?()
    A

     Foo has the value “”

    B

     Foo has the value null

    C

     An exception is thrown

    D

     The code will not compile


    正确答案: B
    解析: 暂无解析