2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > 统计一个字符串中 大写字母 小写字母 数字字符的出现的次数 (不考虑其他字符)。

统计一个字符串中 大写字母 小写字母 数字字符的出现的次数 (不考虑其他字符)。

时间:2020-06-03 05:08:49

相关推荐

统计一个字符串中 大写字母 小写字母 数字字符的出现的次数 (不考虑其他字符)。

package ss1;

/**

*统计一个字符串中 大写字母,小写字母,数字字符的出现的次数,(不考虑其他字符)。

*/

public class Menu {

public static void main(String[] args) {

String s = "Hello132Wworld";

int bigCount=0;

int smallCount=0;

int numberCount=0;

for(int i=0;i<=s.length()-1;i++){

char c = s.charAt(i);

if(c>="0" &&c<="9"){

numberCount++;

}else if(c>="a" &&c<="z"){

smallCount++;

}else if(c>="A" &&c<="Z"){

bigCount++;

}

}

System.out.println("大写字母:"+bigCount+"小写字母:"+smallCount+"数字字符:"+numberCount);

}

}

结果:

大写字母:2小写字母:9数字字符:3

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