写出下面程序的输出结果 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; } }
举一反三
- 以下程序段的结果是( )。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
- 【填空题】INDEX("DATASTRUCTURE", "STR")=________; INDEX("DATASTRUCTURE", "STR",6)=________
- 当输入为 ‘cbabc’ 时,下列程序的输出结果为?s1 = raw_input() index = 0 s2 = '' while index [ len(s1) - 1: if s1[index] ] s1[index + 1]: s2 += s1[index] else: s2 = s2 * 2 index += 1 print s2
- 对于如下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
- index("datastructure","str",1)=