本题统计字符串str中字母a出现的次数,其中str为“(7amp;asdfasdf873eat687al(4a”,字母a存储在字符变量c中,最后打印输出结果。public class javal{public static void main(String[]args){String str=(*amp;7asdf adf873eat687al(4a;char c;int sum=0;int i=0:do{c= ;if( )sum++:i++:}while( );System.out.println(sum=+sum);}}

本题统计字符串str中字母a出现的次数,其中str为“(7&asdfasdf873eat687al(4a”,字母a存储在字符变量c中,最后打印输出结果。

public class javal{

public static void main(String[]args){

String str="(*&7asdf adf873eat687al(4a";

char c;

int sum=0;

int i=0:

do{

c= ;

if( )

sum++:

i++:

}while( );

System.out.println("sum="+sum);

}

}


相关考题:

●试题八阅读下列函数说明和C代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。【程序】#includestdio.hmain(){FILE*fp;charstr[100];inti=0;if((fp=fopen("text.txt" (1) ))==NULL){printf("can't open this file.\n");exit(0);}printf("input astring:\n");gest(str);while(str[i]){if(str[i]=′a′ && str[i]=′z′)str[i]= (2) ;fputc(str[i], (3) );i++;}fclose(fp);fp=fopen("test.txt", (4) );fgets(str,100,fp);printf("%s\n",str);(5) ;}

阅读下列函数说明和C代码,将应填入(n)处的字句写在对应栏内。【说明】以下程序的功能是:从键盘上输入一个字符串,把该字符串中的小写字母转换为大写字母,输出到文件test.txt中,然后从该文件读出字符串并显示出来。【程序】include < stdio. h >main( ){ FILE * fp;char str[100]; int i=0;if((fp=fopen("text.txt"(1))) ==NULL){ printf("can't open this file. \n") ;exit(0) ;}printf(" input astring: \n" ); gest(str);while( str[i] ){ if(str[i] >='a' str[i] <='z')str[i]=(2);fputc(str[i],(3));i++;}fclose(fp);fp=fopen(" test.txt",(4));fgets(str, 100, fp);printf("%s\n" ,str);(5);}

请补充函数fun(),该函数的功能是:把一个字符串中的字符(字母)按从小到大排序,并把这个全部由字母组成的字符串保存在原串中,函数返回这个字符串的长度。例如;输入“cixbr2.3”,如果为bcirx,字符串长度为5。注意:部分源程序给出如下.请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。include <stdio.h>define N 20int fun (char *str){int i=0,j=0,k=-0,m=0;char t;char *p=str;while(*p){if((*p>='A'*p<='Z')||(*p>='a'*p<='z'))【 】p++;}*(str+i)='\0';【 】;while(*(p+j)){k=j;【 】;while (*(p+k)){if(*(p+k)<*(str+m){t=*(str+m);*(str+m)=*(p+k);*(p+k)=t;}k++;}j++;}return i; }main(){char str[81];iht n;clrscr();printf("Input the original string ");gets(str);printf("*** The Original string ***In");puts(str);printf("*** The nwe string ***\n");n=fun(str);puts(str);printf("***The length of new string is:%d***\n",n);}

从键盘输入字符串,统计其中大写字母、小写字母、数字和其他字符出现的个数。

编程:由用户键盘输入次数n和字符串str[10],要求在新线程中显示n次str字符串。

字符串函数strupr(str),可将串中大写字母变成小写字母.

下面对字符串方法描述正确的是A.count() 方法用于统计字符串里某个字符出现的次数B.find() 方法检测字符串中是否包含子字符串 str ,如果包含子字符串返回开始的索引值,否则会报一个异常C.index() 方法检测字符串中是否包含子字符串 str, 如果str不在 返回-1D.title()将字符串的首字母变成大写

从键盘输入一个以“#”结尾的字符串,在字符串中间可以包含空格和换行,统计期中英文字母出现的次数,统计时不区分字母大小写,然后按A-Z的顺序输出字符串中出现的英文字母和出现的次数,最后再输出一个井号。

设 str = 'python' ,想把字符串的第一个字母大写,其他字母还是小写,正确的选项是()A.print(str[0].upper()+str[1:])B.print(str[1].upper()+str[-1:1])C.print(str[0].upper()+str[1:-1])D.print(str[1].upper()+str[2:])