首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是 public class FindKeyWords{ public static void main(String[]args) { String
下面程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是 public class FindKeyWords{ public static void main(String[]args) { String
admin
2013-03-01
87
问题
下面程序的功能是统计字符串中“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 indMdual value" +"through an integer index. For example,if a is an array" +"of inergers,then a
is the ith integer in the array."; int arrayCount=0; int index=-1; String arrayStr="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
解析
程序中变量index为text.indexOf(arrayStr)的返回值,indexOf方法的原型为:public int indexOf(string str),如果字符串参数作为一个子字符串在此对象中出现,则返回第一个这样的子字符串的第一个字符的索引;如果它不作为一个子字符串出现,则返回-1。public int indexOf(string str,int fromIndex)从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引,如果没有指定字符串出现,则返回-1。本程序是判断子字符串是否出现,因此判断结果>=0即可。
转载请注明原文地址:https://kaotiyun.com/show/k52p777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
下列说法中错误的一项是______。
在ODBC标准中,允许使用的数据库连接标准是______。
下列说法中错误的一项是______。
如果在编译Java程序时,编译结果报告说找不到要编译的代码,通常的错误不是如下的______项?
下列程序的输出结果是______。publicclassex23{publicstaticvoidmain(String[]args){
下列说法中错误的一项是______。
在Java语言中有多种实现的机制,下列______技术属于垃圾回收机制。
数据流的类型有______和事务型。
在软件生产过程中,需求信息的给出是
下面是一个Java的应用程序,其输出结果是publicclassTestll{publicstaticvoidmain(Stringargs[]){charc=’i’;for(intn;6;n<11;m+
随机试题
埋弧自动焊前,先把焊剂铺撒在焊缝上大约()厚。
Ⅱ型呼吸衰竭不能给予高浓度吸氧的原因主要是
肾小管性蛋白尿中蛋白升高的是
下列有关胸外心脏按压的叙述错误的是( )。
病毒性肝炎中见明显碎片状坏死和桥接坏死的是
施工质量保证体系的特点包括()。
按照国际惯例,常用的索赔费用的计算方法包括( )。
A、 B、 C、 C
Mostofusfindtheforgettingeasier,butmaybeweshouldworkontheforgivingpart."Holdingontohurtsandnursinggrudges
FamousChristmasPlacesTherearemany【T1】______traditionsinChristmas.【T1】______ThetwofamousChristmasplacesare:1.Mid
最新回复
(
0
)