下列程序的功能是统计字符串中“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条件应为查询成功。