黑马程序员技术交流社区
标题:
统计一个字符串中大写字母字符,小写字母字符,数字字...
[打印本页]
作者:
石头stone
时间:
2016-5-26 21:36
标题:
统计一个字符串中大写字母字符,小写字母字符,数字字...
//统计一个字符串中大写字母字符,小写字母字符,数字字符出现的次数,其他字符出现的次数。
//ABCDEabcd123456!@#$%^
public class Test2_3 {
public static void main(String[] args) {
String str = "ABCDEabcd123456!@#$%^";
int big=0,small=0,num=0,other=0;
char[] ch = str.toCharArray();
for (int i = 0; i < ch.length; i++) {
if (ch[i]>='A'&&ch[i]<='Z') {
big++;
}else if (ch[i]>='a'&&ch[i]<='z'){
small++;
}else if (ch[i]>='0'&&ch[i]<='9'){
num++;
}else{
other++;
}
}
System.out.println("小写" + small + "个,大写" + big + ",数字" + num + "个,其他" + other + "个");
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2