首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。 public class Fi ndKey Words{ public static void mai n(sri ng[]args){ sti ng text
下列程序的功能是统计字符串中“array”的个数,在程序的空白处应填入的正确选项是( )。 public class Fi ndKey Words{ public static void mai n(sri ng[]args){ sti ng text
admin
2012-12-02
42
问题
下列程序的功能是统计字符串中“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://kaotiyun.com/show/u6ID777K
本试题收录于:
二级Java题库NCRE全国计算机二级分类
0
二级Java
NCRE全国计算机二级
相关试题推荐
政府为了保护农业生产者,对部分农业产品规定了保护价格。为了采取这种价格政策,应采取相应的措施是()。
消化系统是保证人体新陈代谢正常进行的一个重要系统,是由消化管和消化腺两大部分组成,下列器官或腺体不属于消化系统的是()。
在南极洲,尽管气候异常寒冷,但在南极维多利亚大煤田的煤炭储存量非常大,而且煤的质地特别好。其最有可能的原因是()。
民俗是文化的一种表现形态,即传统与文化的活态形式。它是经过于百年岁月的淘洗留下来的文化精华与现实结合的产物。民俗对于特定的群体有强烈的认同功能,对于当代社会的建设,具有不可替代的作用。这段文字是从什么角度来定义“民俗”的()。
作为一名志愿者,小王奉献社会、乐于助人,按照斯普兰格对性格类型的划分,小王属于
设在SQLServer某数据库中有房屋出租表,表的定义如下:CREATETABLE租表(房屋号char(10),出租日期datetime,租期intnotnull,--月数到期日期datet
设有课程表(课程号,课程名,开课学期)和选课表(学号,课程号,成绩),现要利用开窗函数查询每门课程的课程名、开课学期及选该门课的学生人数(不包括没人选的课程)。请补全下列语句:SELECTDISTINCT课程名,开课学期,COUNT(*)OVER(【4
本题中,窗口的背景色为系统桌面的颜色,在窗口中分别画了空心和实心的黑色矩形、深灰色圆角矩形和浅灰色椭圆形,并且画了白色粗体的“欢迎学习Java!”字符串。importjava.awt.*;importjavax.swing.*;publiccl
某二叉树有5个度为2的结点,则该二叉树中的叶子结点数是()。
下列关于线程优先级的说法中,正确的是()。
随机试题
课外校外教育的特点是()。
门脉性肝硬化组织学变化,下列哪项不正确
规定列基本医疗保险基金不予支付的药品目录的是不能纳入基本医疗保险用药范围的是
质量管理国际标准化的先河是()。
当工程分包时,分包单位应当对()负责。
施工项目成本控制工作从施工项目()开始直到竣工验收,贯穿于全过程。
我国建立社会主义市场经济体制的中心环节是()。
传递信息的速度最快的是()沟通。
EgyptianwinehasanextensivehistorywithinthehistoryofEgypfiancivilization.Grapeswerenot【C1】______tothelandscapeof
Ayoungconsultant’slifeistiring.A【C1】______weekstartsbeforedawnonMonday,witharushtotheairportanda【C2】______to
最新回复
(
0
)