下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。 public class Fi ndKey Words{ public static void mai n(sri ng[]args){ sti ng text

admin2012-12-02  40

问题 下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是(  )。
public class Fi ndKey Words{
public static void mai n(sri ng[]args){
sti ng text =
"An array is a data structur that stores a collection of"
+"values of the same type .You access eachi ndividu-al value"
+"through an i nteger i ndex .For example ,if a is anarray"
+"of i nergers ,then a[i]is the ith i nteger i n the ar-ray .";
Int arrayCount =0;
Int idex =-1;
Sti ng arrarStr ="array";
Index =text .i ndexof(arrayStr);
While(i nde_________x 0){
++arrayCount ;
Index +=arrayStr .length();
Index =text .i ndexof(arrayStr ,i ndex);

Syste m.out .pri ntln
("the text contai ns"+arrayCount +"arrays");


选项 A、<
B、=
C、<=
D、>=

答案D

解析 在字符串中查询指定的字符或子串,可用i ndexof()方法,如查询成功,返回所查字符的位置。如不成功,返回-1,从下面程序可以看出,While 条件应为查询成功。
转载请注明原文地址:https://jikaoti.com/ti/w5kiFFFM
0

相关试题推荐
最新回复(0)