当前位置:三九宝宝网 → 宝宝教育 → 写作范文 → 正文

c输入一行字符分别统计出英文字母空格数字和其他字符的个数

更新:12-25 整理:39baobao.com
字体:

[java统计字符串中每个字母有多少个]如下代码提供了三种方式统计一个字符串中出现的大小写字母和其他字符: class Test{ publicstatic void main(String[] args) { String str = "abAM1,!23"; int cntU = 0; //大写...+阅读

"搜狗问问"

// 错误1: 标准C++除了兼容, 一般是不是用字符数组的, 而是用string

// 错误2: cin >> a 这种方式并不能读入空格

// 错误3:a[j]<='z'&&a[j]>='a'||a[j]<='Z'&&a[j]>='A'这样写法有歧义

// 楼主用的char数组, 这里就在楼主的基础上改了, 就不用string做了

#include

#include

using namespace std;

int main(void){

int j;

int m = 0;

int n = 0;

int l = 0;

int k = 0;

char a[100];

cout <<; "输入一行字符" << endl;

cin.getline(a, 99); // 使用成员函数GetLine才可以读取空格

for (j = 0; j != strlen(a); ++j)

if (a[j] >= 48 && a[j] <= 57) // 数字

++m;

else if (a[j] == 32) // 空格

++n;

else if ((a[j] >= 97 && a[j] <= 122) || (a[j] >= 65 && a[j] <= 90)) // 字母

++l;

else

++k;

cout << "the sum of number " << m << endl;

cout << "the sum of blank space " << n << endl;

cout << "the sum of letler " << l << endl;

cout << "the sum of others " << k << endl;

system("PAUSE>NUL");

return 0;

}

刚才说法有问题

错误1和错误3

应该叫做

注意点1和注意点3

嘿嘿

本文地址:https://www.39baobao.com/show/33_13757.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

用java怎么实现统计一英文文档里各个英语字母的个数及所占百分比import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Test { public static void main(String[] args) throws IOExcept...

使用下列方法头编写一个方法统计字母在字符串中出现的个数判断一下就好了 public class Text{ /** * param args * throws IOException */ public static void main(String[] args) { System.out.println(countLetters("java 2008"));...

java统计字符串中字母的个数如何修改import java.util.Scanner; /** * 统计字符串中数字,字母,空格,其他字符的个数 * author Administrator * */ public class Data01 { public static void main(String[] args)...

求用java编一个计算有多少个数字字母其他字符的代码代码如下: import java.util.Scanner; /** * 统计字符串中数字,字母,空格,其他字符的个数 * author young * */ public class Data01 { public static void main(String[] args)...

java输入字符串统计字母单词数字句子个数1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 importjava.util.*; classTest{ publicstaticvoidmain(String[] args){ Scanner s=newScanner(System.in); String str=" "+s.nex...

java编程:输入一个字符串计算字符串中所包含的字母个数数字public class Practise1 { /** * param args */ public static void main(String[] args) { Practise1.tongJi("afajofiGILB76097你好世界"); } public static void tongJi(Str...

Java键盘输入一个字符串分别统计出该字符串中所有数字大写英参考代码如下: #include<stdio.h> int main() { char ch; int A,a,n,other; A=a=n=other=0; while((ch=getchar())!='\n'){ if(ch>='a'&ch<='z') ++a; else if(ch>='A'&ch<='...

C语言输入一行字符分别统计出其中英文字母空格数字和其已改,看注释 #include<stdio.h> int main() { int a,b,c,d,f; char e[100]; a=b=c=f=0; printf("请输入一行字符\n"); gets(e); //改gets for(d=0;e[d]!='\0';d++) //改'\0' if(('...

输入一行字符统计该行字符包含英文字母空格数字和其他字符#include<stdio.h> void main() { int word,digital,other,space; word=digital=other=space=0; char string[20],*p; printf("Input:"); gets(string);// //*string=0; p=str...