计算机二级考试

解析:下面程序段的输出结果为 public class MyClass

来源:网考网计算机二级 所有评论

【单选题】 下面程序段的输出结果为 public class MyClass { public static void main(String args[]) { String s="Hello! How are you"; System.out.println(s.LastIndexOf("o",16); } }
A.16
B.o
C.u
D.17

网考网参考答案:A
网考网解析:

[解析] 本题考查字符串类中常用成员函数的用法。String类的成员函数lastIndexOf()的原型是:public int lastIndexOf(String str, int fromIndex)。它用于获得字符串str在给定字符串中从fromIndex位置往回搜索第一次出现的地方。需要注意的是,在字符串中,下标是从0开始的。所以对于字符串s,下标为16的字母正好是o,从这里往前寻找字符串“o”第一次出现的位置,正好就是字符串中。它本身所在的位置。故 s.lastIndexOf(“o”,16)返回的结果就是16。 查看试题解析出处>>

相关推荐

发布评论 查看全部评论