单选题下列程序的功能是统计字符串中“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   +thro

题目
单选题
下列程序的功能是统计字符串中“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

>=


相似考题
更多“下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(  )。public class F”相关问题
  • 第1题:

    ( 30 )下列程序的功能是统计字符串中 “ array ” 的个数,在程序的空白处应填入的正确选项是

    public class FindKey Word s{

    public static void main(sring[] args){

    sting 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 idex = -1;

    Sting arrarStr = ” array ” ;

    Index = text.indexof(arrayStr);

    While(index______ 0) {

    ++arrayCount;

    Index += arrayStr.length();

    Index = text.indexof(arrayStr,index);

    }

    System.out.println

    ( “ the text contains ” + arrayCount + “ arrays ” );

    }

    }

    A) <

    B) =

    C) <=

    D) >=


    正确答案:D

  • 第2题:

    下列程序的功能是为变量赋值,程序运行后,输出i=51。请改动main方法中的错误,使程序能够正确编译、运行并输出正确的结果。

    注意:不改动程序结构。

    class A

    {

    private int a;

    public void setA (int x)

    {

    a=x;

    }

    public int getA()

    {

    return a;

    }

    }

    public class MethodTest

    {

    public static void main(String args[])

    {

    A a=A();

    a.getA(51);

    int i=a.getA();

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

    }

    }


    正确答案:改正后的main方法如下: public static void main(String args[]) { A a=new A(); a.getA(51); int i=a.getA(); System.out.println("i="+i); }
    改正后的main方法如下: public static void main(String args[]) { A a=new A(); a.getA(51); int i=a.getA(); System.out.println("i="+i); } 解析:本题综合考查类及类成员的定义与使用方面的知识。该程序中定义了两个类:A和MethodTest,类A中封装了一个私有的成员变量a和两个公有的方法setA和getA。在类MethodTest中包含了main方法。创建对象应使用new操作符来实例化对象,程序在创建对象a时未使用new,故存在错误。由于a是对象a的私有变量,在main方法中不能直接访问,只能通过对象a的公有方法setA和getA来访问。公有方法setA的功能是将传递回来的参数值赋给a,所以应当调用setA方法来为变量a赋值。

  • 第3题:

    下面程序的功能是将数组array下标为奇数的元素相乘(数组的位置是从0开始的),并将乘积存放到变量 total中。请在程序的每条横线处填写—个位运算符,使程序的功能完整。

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

    源程序代码文件清单如下:

    public class JiShuJi

    {

    public static void main(String args[])

    {

    int array[ ]={1,2,3,5,7,9};

    long total=

    for(int i=1;i<=______;i++)

    {

    ______;

    i++;

    }

    System.out.println(total);

    }

    }


    正确答案:array.length-1 total*=array[i]
    array.length-1 total*=array[i] 解析:本题主要考查for循环语句和数组的知识。解答本题的关键是熟练掌握for循环语句和数组的知识。一个for循环语句一般应包含4部分内容。①初始化部分:用来设置循环控制的一些初始条件,如设置计数器等。②循环体部分:这是反复执行的一段代码,可以是单一的一条语句,也可以是复合语句(代码块)。③迭代部分;用来修改循环控制条件。常常在本次循环结束,下一次循环开始前执行。例如,使计数器递增或递减。④判断部分:也称终止部分。是一个关系表达式或逻辑表达式,其值用来判断是否满足循环终止条件。每执行一次循环都要对该表达式求值。解答循环语句时要抓住这4个部分。

  • 第4题:

    下列程序的运行结果是______。include class Base { public: void f(int x){cout<<“B

    下列程序的运行结果是______。

    include<iostream.h>

    class Base

    {

    public:

    void f(int x){cout<<“Base:”<<x<<endl;}

    );

    class Derived:public Base

    {

    public:

    void f(char*str){cout<<“Derived:”<<str<<endl;}

    };

    void main(void)

    {

    Base*pd=ne


    正确答案:Base:97。
    Base:97。 解析: 本题主要考查两个知识点,一是基类指针可以指向派生类对象,并可以访问派生类的所有成员。二是在函数重载中进行隐式类型转换。如pd->f(‘a’);系统到底调用哪个重载函数呢?实参既不是派生类中的形参,也不是基类中f函数的形参类型。此时系统根据就近原则和从高优先级到低优先级的规则尝试隐式转换。单字符更接近整数,故调用的是基类的f函数。

  • 第5题:

    阅读下面程序 public class Test2______ { public static void main(String[] args){ Thread t=new Test2(); t. start(); } public void run(){ System. out. priatln("How are you. "); } } 在程序下画线处填入的正确的选项是

    A.implements Thread

    B.extends Runnable

    C.implements Runnable

    D.extends Thread


    正确答案:D
    解析:Thread类是多线程基类,多线程启动类必须继承此类。而实现Runnable接口的类能作为多线程的一个执行任务,一般作为参数传给新的Thread类。

  • 第6题:

    下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。

    A.<

    B.=

    C.<=

    D.>=


    正确答案:D
    在字符串中查询指定的字符或子串,可用indexof()方法,如查询成功,返回所查字符的位置。如不成功,返回-l,从下面程序可以看出,While条件应为查询成功。

  • 第7题:

    有下列程序:includeusing namespace std;class ONE{ public:virtual void f(){COUt<<"

    有下列程序:

    include<iostream>

    using namespace std;

    class ONE

    {

    public:

    virtual void f(){COUt<<"1";}

    };

    c1assTWO:public ONE

    {

    public:

    TWO(){cout<<"2";}

    };

    class THREE:public TWO

    {

    pub


    正确答案:2213
    2213 解析: 此题考查的是派生类的构造和析构函数。建立TWO的对象bb时,调用TWO的构造函数,输出“2”;THREE类又派生于TWO类,所以建立THREE类的对象cc时又会输出“2”;ONE类的对象指针p指向了THREE类的ONE类的虚函数f(),输出“1”;最后调用THREE类的f(),输出“3”。故最终的输出结果是2213。

  • 第8题:

    下列给定程序中,函数fun的功能是:从形参SS所指字符串数组中,删除所有串长超过k的字符串,函数 返回剩余字符串的个数。ss所指字符串数组中共有N个字符串,且串长小于M。

    请在程序的下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。注意:部分源程序在文件BLANKl.C中。

    不得增行或删行.也不得更改程序的结构!


    正确答案:
    (1)N(2)k(3)ss[i]【考点分析】本题考查:for循环语句;ff语句条件表达式;字符串拷贝函数strcpy的使用。【解题思路】填空1:for循环语句作用是遍历字符串数组中的每一个字符串,所以循环变量i的循环条件是i<N。填空2:题目要求删除串长度小于k的字符串,所以if条件语句的条件表达式是len<=k。。填空3:通过字符串拷贝函数将串长不大于k的字符串另存,并记录个数。【解题宝典】字符串拷贝函数strcpy,其格式为:strcpy(字符数组名1,字符数组名2)功能:把字符数组2中的字符串拷贝到字符数组l中。字符串结束标识‘、0’也一同拷贝。字符数名2,也可以是一个字符串常量。这时相当于把一个字符串赋予一个字符数组。

  • 第9题:

    下列哪个选项的java源文件程序段是不正确的? ( )

    A.package testpackage; public class Test{ }

    B.import java.io.*; package testpackage; public class Test{ }

    C.import java.i.*; class Person{} public class Test{ }

    D.import java.io.*; import java.awt.*; public class Test { }


    正确答案:B

  • 第10题:

    阅读下面程序 public class Test2 ______ { public static void main(String[] args) { Thread t=new Test2(); t.start(); } public void run() { System.out.println("How are you."); } } 程序中下画线处应填入的正确选项是

    A.implements Thread

    B.extends Runnable

    C.implements Runnable

    D.extends Thread


    正确答案:D

  • 第11题:

    下列程序片段中,能通过编译的是( )。 A.public abstract class Animal{ public void speak;}S

    下列程序片段中,能通过编译的是( )。

    A.public abstract class Animal{ public void speak;}

    B.public abstract class Animal{ public void speak{);}

    C.public class Animal{ pubilc abstract void speak;}

    D.public abstract class Animal{ pubile abstract void speak{};}


    正确答案:A
    A。【解析】Java中一个类是一个abstract类的子类,它必须具体实现父类的abstract方法。如果一个类中含有abstract方法,那么这个类必须用abstract来修饰(abstract类也可以没有abstract方法)。有abstract方法的父类只声明,由继承它的子类实现。所以选A。

  • 第12题:

    ( 11 )下列程序的功能是统计命令行参数的个数,请在下划线处填上适当的代码。

    public class Length{

    public static void main(String args[]){

    System.out.println( " number of String args: " +args. 【 11 】 );

    }

    }


    正确答案:

  • 第13题:

    以下程序的功能是统计字符串A中出现字符串B的次数,然后输出,请在填空[9]处填入适当的程序完成功能。


    正确答案:InStr(a$bS)或c
    InStr(a$,bS)或c 解析:字符函数InStr()的功能是在第一个字符串参数中寻找第二个字符串参数出现的位置,如果在第一个字符串中不能找到第二个字符串,返回值0。当第一个字符串找到第二个字符串时,则只返回第一次找到的位置。因此,程序中在A中找到一个字符串B后,必须对字符串A进行截取操作,去掉找到的字符串B,不然程序会陷入死循环。

  • 第14题:

    下面的程序的功能是将数组array下标为奇数的元素相乘(数组的位置是从0开始的),并将乘积存放到变量total中。请在程序的每条横线处填入适当的语句,使程序的功能完整。

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

    public class JiShuJi

    {

    public static void main(String args[ ])

    {

    int array[ ]={1,2,3,5,7,9};

    long total= ________________________;

    for(int i=1;i<=__________________ i++)

    {

    ____________________

    i++;

    }

    System.out.println(total);

    }

    }


    正确答案:1 array.length-1; total*=array[i];
    1 array.length-1; total*=array[i]; 解析:本题主要考查for循环语句和数组的知识。解答本题的关键是熟练掌握for循环语句和数组的知识。一个for循环语句一般应包含4部分内容:(1)初始化部分:用来设置循环控制的一些初始条件,如设置计数器等。(2)循环体部分:这是反复执行的一段代码,可以是单一的一条语句,也可以是复合语句(代码块)。(3)迭代部分:用来修改循环控制条件。常常在本次循环结束,下一次循环开始前执行。例如,使计数器递增或递减。(4)判断部分:也称终止部分。是一个关系表达式或布尔逻辑表达式,其值用来判断是否满足循环终止条件。每执行一次循环都要对该表达式求值。解答循环语句题要抓住这四个部分。

  • 第15题:

    如下程序的输出是includeusing namespace std;class Base{public:Base( ){cout<<"BB"

    如下程序的输出是 #include<iostream> using namespace std; class Base{ public: Base( ){cout<<"BB";f( );} void f( ){cout<<"Bf";} }; class Derived:public Base{ public: Derived( ){eout<<"DD";} void f( ){cout<<"Df";} }; int main( ){Derived d;return 0;}

    A.BBBff)D

    B.BBDfDDDf

    C.DD

    D.DDBBBf


    正确答案:A
    解析:当创建派生类对象时,首先调用基类的构造函数,最后调用派生类的构造函数。

  • 第16题:

    在下列程序画线处填入的正确语句是()。includeusing namespace std;classBase{public:

    在下列程序画线处填入的正确语句是( )。 #include <iostream> using namespace std; class Base { public: void fun() { cout<<"Base::fun",<<end1; } }; class Derived:public Base { void fun() { ______________ //显式调

    A.fun();

    B.Base.fun();

    C.Base::fun();

    D.Base->fun();


    正确答案:C
    解析:本题主要考核作用域分辨符的使用。作用域分辨符“::”可以用来限定要访问的成员所在类的名称。

  • 第17题:

    在下列程序的空白处,应填入的正确选项是( )。

    A.start( )

    B.close( )

    C.read( )

    D.write( )


    正确答案:B
    close方法关闭写文件。

  • 第18题:

    下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。 public class FindKeyWords( public static void main(sring[]args){ sting text= "An array is a data structur that stores a eollection of" +"values of the same type.You access each individu- al value" +"through an integer index.For example.if a is an array" +"of inergers,then all]is the ith integer in the ar- ray."; Int arrayCount=0; Int idex=-l; Sting arrarStr="array": Index=text.indexof(arrayStr); While(index 0){ ++arrayCount: Index+=arrayStr.1ength; Index=text.indexof(arrayStr,index); } System.OUt.println ("the text contains"+arrayCount+"arrays"); } }

    A.<

    B.=

    C.<=

    D.>=


    正确答案:D
    D。【解析】在字符串中查询指定的字符或子串,可用indexof方法,如查询成功,返回所查字符的位置。如不成功,返回-l,从下面程序可以看出,While条件应为查询成功。

  • 第19题:

    下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。 publicclassFindKeyWords{ publicstaticvoidmain(sring[]args){ stingtext= “Anarrayisadatastructurthatstoresacollectionof” +“valuesofthesametype.YOUaccesseachindividualvalue'’ +“throughanintegerindex.Forexample,ifaiSanarray” +“of inergers,thena[i]iSthe ith integer in thearray.”; In tarrayCount=0; Intidex=-1; Sting arrarStr=“array”; IndeX=text.indexof(arrayStr); While(index______0){ ++arrayCount; Index+=arrayStr.length(); IndeX=text.indexof(arrayStr,indeX); } SyStem.out.phntln (“thetextcontains”+arrayCount+“arrays”); } }

    A.<

    B.=

    C.<=

    D.>=


    正确答案:D
    解析:在字符串中查询指定的字符或子串,可用indexof()方法,如查询成功,返回所查字符的位置。如不成功,返回-1,从下面程序可以看出,While条件应为查询成功。

  • 第20题:

    在下列程序的空白处,应填入的正确选项是( )。

    A.WriterObject

    B.Writer

    C.BufferedWriter

    D.writerObject


    正确答案:D
    本题考查的是输入/输出及文件操作,writerObject方法是向数据流中写入数据。

  • 第21题:

    有下列程序: include using namespace std; class Base { public: Base(){cout<<"B

    有下列程序: #include<iosteram.h> using namespace std; class Base { public: Base(){cout<<"BB"; f(); } void f(){cout<<"Bf";} }; class Derived:public Base { public: Derived(){cout<<"D

    A.BBBfDD

    B.BBDfDDDf

    C.DD

    D.DDBBBf


    正确答案:A
    解析: 此题考查的是类的继承和派生。派生类执行构造函数的一般次序:首先调用基类构造函数;然后调用成员对象的构造函数;最后是派生类构造函数中的内容。题目中定义派生类对象d时,先调用基类Base的构造函数,输出BBBf,然后调用派生类Derived的构造函数,输出DD。

  • 第22题:

    下面程序的功能是()。include include using namespace std;int main (){ in

    下面程序的功能是( )。 #include <iostream> #include <string> using namespace std; int main () { int i=1, n=0; char s[80],*p; p=s; strcpy(p,"It is a book.."); for (; *p !=' \0' ;p++) { if(*p=='') i=0; else if (i==0) { n++; i=1; } } cout<<"n=" <<n<<end1; return 0; }

    A.统计字符串中的单词个数

    B.统计字符串中的空格个数

    C.统计字符串中的字母个数

    D.统计字符串中的全部字符个数


    正确答案:B
    解析:本题通过for循环对字符串进行扫描,遇到'\0'结束扫描。程序首先将i的值置为1,n的值置为0。在for循环中,通过if语句判断*p指向的字符是否为空格,如果是空格则将i的值置为0,而在elseif语句,如果i的值为0,则n++,然后将i的值重新置为1。如此反复,最后统计出字符串中的空格个数。

  • 第23题:

    下列的程序的功能是求2~100之间的素数,程序中划线部分应填入的选项是 public class Testnn { public static void main(String args[]) { Labell: for(int i=2;i<100;i++) { for(int j=2;j<i;j++) { if(i%j==______)continue Labell; } System.out.println(i); } } }

    A.0

    B.1

    C.i

    D.j


    正确答案:A
    解析:根据素数的定义,如果一个数只能分解成1和本身这两个乘积因子,那么这个数就是素数,如5只能等于是1*5,而6不仅能等于1*6,还能等于2*3,所以5是素数,而6是合数;有了素数的概念便可以用双重for语句进行判断,外层for(inti=2;i100;i++)是让被测试的数移动的;而里面的for(intj=2;ji;j++),是用来判断被测试的数能不能被分解为除去1和它本身以外的位于1和本身之间的数,如果能,则有i%j==0,回到第一个特环,接着继续执行。

  • 第24题:

    程序中有一空白处,需要填入一条语句使程序完成其功能。下列选项中错误的语句是()。

    • A、flag=False
    • B、flag=Notflag
    • C、flag=True
    • D、ExitDo

    正确答案:C