2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > java 输入一串字符统计大写字母个数小写字母个数及特殊符号并输出

java 输入一串字符统计大写字母个数小写字母个数及特殊符号并输出

时间:2023-11-01 11:45:28

相关推荐

java 输入一串字符统计大写字母个数小写字母个数及特殊符号并输出

```java//输入一串字符统计大写字母个数小写字母个数及特殊符号并输出public static void test5(String str){char[] s = str.toCharArray();int a=0,b=0,c=0,d=0;for (char ss : s){if (ss>='A' && ss<='Z'){a++;}else if(ss>='a' && ss<='z'){b++;}else if(ss>='0' && ss<='9'){c++;}else{d++;}}System.out.println("大写字母有"+a+"个");System.out.println("小写字母有"+b+"个");System.out.println("数字有"+c+"个");System.out.println("特殊符号有"+d+"个");/*C:char t;int a=0,b=0,c=0,d=0;while( (t=getchar()) != '\n' ){if (t>='A' && t<='Z'){a++;}else if(t>='a' && t<='z'){b++;}else if(t>='0' && t<='9'){c++;}else{d++;}}printf("大写:%d 小写:%d 数字:%d 特殊字符:%d ",a,b,c,d);*/}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。