统计一个字符串中大写字母,小写字母,数字字符的出现的次数,(不考虑其他字符)。
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
字符常量与字符串常量的区别

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。