以下程序段的结果是( )。String str="abcdefghijk";String s="bcde";int index=0;index=str.indexOf(s,index);str=str.substring(0,index)+str.substring(index+4);System.out.println(str);
A: abcdefghijk
B: afghijk
C: abcde
D: bcdefghijk
A: abcdefghijk
B: afghijk
C: abcde
D: bcdefghijk
举一反三
- 以下哪个方法用来从字符串中获取一个字符。 ( ) A: indexOf(String str) B: substring(int beginIndex, int endIndex) C: concat(String str) D: charAt(int index)
- 以下哪个方法用来从字符串中获取一个字符? A: indexOf(String str) B: split(String str,char ch) C: concat(String str) D: charAt(int index)
- 【填空题】INDEX("DATASTRUCTURE", "STR")=________; INDEX("DATASTRUCTURE", "STR",6)=________
- 对于如下C程序:#include [stdio.h] void Func (char *); int main() { char str[20]; scanf ("%s", str); Func(str); printf ("%s\n", str);} void Func(char *str) { int i = 0; int index = 0; char temp; while (str[index] != '\0'){ index++; } for (i = 0; i < index/2 ; i++){ temp = str[i]; str[i] = str[index - 1 - i]; str[index - 1 - i] = temp; }}如果输入为“abcd”,则输出为:[/i][/i] A: abcd B: dcba C: dcdc D: abab
- 写出下面程序的输出结果 publicclassTestjava{ publicstaticvoidmain(String[]args){ Stringstr="abbaefabbewbvwabbswgfga"; System.out.println("count="+getSubCount(str,"abb")); } publicstaticintgetSubCount(Stringstr,Stringkey){ intcount=0; intindex=0; while((index=str.indexOf(key,index))!=-1){ System.out.println("index="+index); index=index+key.length(); count++; } returncount; } }